Coin de Gamma
2 years ago
5 changed files with 104 additions and 0 deletions
@ -0,0 +1,5 @@
|
||||
Generate primes list before execution |
||||
|
||||
``` |
||||
rustc compute_primes.rs && ./compute_primes > primes.txt |
||||
``` |
@ -0,0 +1,36 @@
|
||||
const SIZE: usize = 1500000; |
||||
type Rs = [bool; SIZE + 1]; |
||||
|
||||
fn remove_divs(m: usize, xs: &mut Rs) { |
||||
let mut i = m + m; |
||||
while i <= SIZE { |
||||
xs[i] = false; |
||||
i += m; |
||||
} |
||||
} |
||||
|
||||
fn get_next_p(m_from: usize, xs: &Rs) -> Option<usize> { |
||||
for k in (m_from + 1)..=SIZE { |
||||
if xs[k] { return Some(k); }
|
||||
} |
||||
return None; |
||||
} |
||||
|
||||
fn main() { |
||||
let mut xs: Rs = [true; SIZE + 1]; |
||||
let mut q: usize = 1; |
||||
let mut count = 0; |
||||
loop { |
||||
match get_next_p(q, &xs) { |
||||
Some(p) => {
|
||||
q = p;
|
||||
count += 1; |
||||
println!("{}", p); |
||||
if count == 500 { break; } |
||||
},
|
||||
None => break
|
||||
} |
||||
remove_divs(q, &mut xs); |
||||
} |
||||
// println!("[{}]: {}", count, q);
|
||||
} |
@ -0,0 +1,34 @@
|
||||
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(); |
||||
return lines.map(|line| line.unwrap().parse::<u32>().unwrap()) |
||||
.collect();
|
||||
} |
||||
|
||||
fn divs_num_test(n: u32) -> u32 { |
||||
let mut res = 0; |
||||
for i in 1..n { |
||||
if n % i == 0 { res += 1; } |
||||
} |
||||
return res; |
||||
} |
||||
|
||||
fn main() { |
||||
let ps = get_ps(); |
||||
let mut n = 1; |
||||
let mut best_dn = 1; |
||||
for k in 2..50000 { |
||||
n += k; |
||||
let dn = 500; //500; //divs_num(n);
|
||||
//if dn > best_dn {
|
||||
// best_dn = dn;
|
||||
//println!("[{}]{}:{}",k, n, dn);
|
||||
//}
|
||||
} |
||||
} |
@ -0,0 +1,26 @@
|
||||
use std::fs::File; |
||||
use std::io::{ self, BufRead, BufReader }; |
||||
|
||||
const PS_SIZE: usize = 500usize; |
||||
|
||||
|
||||
fn divs_num(n: u32) -> u32 { |
||||
let mut res = 0; |
||||
for i in 1..n { |
||||
if n % i == 0 { res += 1; } |
||||
} |
||||
return res; |
||||
} |
||||
|
||||
fn main() { |
||||
let mut n = 1; |
||||
let mut best_dn = 1; |
||||
for k in 2..50000 { |
||||
n += k; |
||||
let dn = divs_num(n); |
||||
if dn > best_dn { |
||||
best_dn = dn; |
||||
println!("[{}]{}:{}",k, n, dn); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue