Created
September 13, 2020 00:42
-
-
Save kinoshita-lab/e4573db0161ad8ff0651deba6c0c2e1f to your computer and use it in GitHub Desktop.
project euler problem 10
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
fn is_prime(val: u64) -> bool { | |
let end = |current_val: u64| -> bool { current_val * current_val > val }; | |
let mut i = 2; | |
loop { | |
if end(i) { | |
return true; | |
} | |
if (val % i) == 0 { | |
return false; | |
} | |
i += 1; | |
} | |
} | |
fn main() { | |
const UPPER: u64 = 2 * 1000000; | |
let sum: u64 = (2..=UPPER).filter(|i| is_prime(*i as u64)).sum(); | |
println!("{:?}", sum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment