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.
35 lines
802 B
35 lines
802 B
const SIZE: usize = 1500000; // found this with manual binary search, it's legal! :) |
|
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; |
|
if count == 10_001 { break; } |
|
}, |
|
None => break |
|
} |
|
remove_divs(q, &mut xs); |
|
} |
|
println!("[{}]: {}", count, q); |
|
}
|
|
|