solutions: 10
This commit is contained in:
parent
8448a97a58
commit
83b2aa0782
30
summation_of_primes.rs
Normal file
30
summation_of_primes.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
fn is_prime(num: u64) -> bool {
|
||||
let prime: bool = true;
|
||||
match num {
|
||||
0..=1 => false,
|
||||
2 => true,
|
||||
num if num % 2 == 0 => false,
|
||||
_ => {
|
||||
for i in (3..=((num as f64).sqrt() as u64)).step_by(2) {
|
||||
if num % i == 0 {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
prime
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut increment: u64 = 1;
|
||||
let mut total: u64 = 0;
|
||||
|
||||
while increment < 2000000 {
|
||||
if is_prime(increment) {
|
||||
total += increment;
|
||||
}
|
||||
increment += 1
|
||||
}
|
||||
|
||||
println!("{:?}", total);
|
||||
}
|
Loading…
Reference in a new issue