-
-
Save jakobrs/aafc4e70716bbd1c645e31951c313e96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::time::Instant; | |
// From jakobrs/primes, using the kimwalisch/primesieve library | |
use primesieve::PrimesieveIterator; | |
fn main() { | |
for n in 5..=20 { | |
let count = ((5. / 4. * n as f64).exp() / n as f64) as u64; | |
let before = Instant::now(); | |
let (v, i) = PrimesieveIterator::new_start_stop(1, count) | |
.enumerate() | |
.skip(1) | |
.take(count as usize) | |
.map(|(i, p)| { | |
let i = i as i64; | |
let p = p as i64; | |
let res = n * i + 1 - p; | |
(res, i) | |
}) | |
.max() | |
.unwrap(); | |
println!( | |
"V_{n} = {v} (at i = {i}) in {elapsed:?}", | |
elapsed = before.elapsed() | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment