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.

37 lines
781 B

2 years ago
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);
}