Browse Source

012 ok

master
Coin de Gamma 2 years ago
parent
commit
56a7612fa8
  1. 32
      012/main.rs
  2. 12
      012/main_basic.rs

32
012/main.rs

@ -2,8 +2,6 @@ use std::fs::File;
use std::io::{ self, BufRead, BufReader };
const PS_SIZE: usize = 500usize;
fn get_ps() -> Vec<u32> {
let file = File::open("primes.txt").unwrap();
let lines = io::BufReader::new(file).lines();
@ -11,11 +9,23 @@ fn get_ps() -> Vec<u32> {
.collect();
}
fn divs_num_test(n: u32) -> u32 {
fn div_num(ps: &Vec<u32>, n: u32) -> u32 {
fn max_div(m: u32, k: u32) -> u32 {
let mut res = 0;
for i in 1..n {
if n % i == 0 { res += 1; }
let mut mm = m;
while mm % k == 0 {
mm /= k;
res += 1;
}
res
}
let mut res = 1;
for p in ps {
let md = max_div(n, *p) + 1;
res *= md;
}
return res;
}
@ -23,12 +33,12 @@ fn main() {
let ps = get_ps();
let mut n = 1;
let mut best_dn = 1;
for k in 2..50000 {
for k in 2..80000 {
n += k;
let dn = 500; //500; //divs_num(n);
//if dn > best_dn {
// best_dn = dn;
//println!("[{}]{}:{}",k, n, dn);
//}
let dn = div_num(&ps, n);
if dn > best_dn {
best_dn = dn;
println!("[{}]{}:{}", k, n, dn);
}
}
}

12
012/main_basic.rs

@ -1,12 +1,6 @@
use std::fs::File;
use std::io::{ self, BufRead, BufReader };
const PS_SIZE: usize = 500usize;
fn divs_num(n: u32) -> u32 {
fn div_num(n: u32) -> u32 {
let mut res = 0;
for i in 1..n {
for i in 1..=n {
if n % i == 0 { res += 1; }
}
return res;
@ -17,7 +11,7 @@ fn main() {
let mut best_dn = 1;
for k in 2..50000 {
n += k;
let dn = divs_num(n);
let dn = div_num(n);
if dn > best_dn {
best_dn = dn;
println!("[{}]{}:{}",k, n, dn);

Loading…
Cancel
Save