You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
909 B

use std::fs::File;
use std::io::{ self, BufRead, BufReader };
fn get_ps() -> Vec<u32> {
let file = File::open("primes.txt").unwrap();
let lines = io::BufReader::new(file).lines();
return lines.map(|line| line.unwrap().parse::<u32>().unwrap())
.collect();
}
fn div_num(ps: &Vec<u32>, n: u32) -> u32 {
fn max_div(m: u32, k: u32) -> u32 {
let mut res = 0;
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;
}
fn main() {
let ps = get_ps();
let mut n = 1;
let mut best_dn = 1;
for k in 2..80000 {
n += k;
let dn = div_num(&ps, n);
if dn > best_dn {
best_dn = dn;
println!("[{}]{}:{}", k, n, dn);
}
}
}