-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution10.java
More file actions
32 lines (32 loc) · 919 Bytes
/
Copy pathSolution10.java
File metadata and controls
32 lines (32 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class Solution10{
static boolean isPrime(int num){
if(num <= 1){
return false;
}
else if(num <= 3){
return true;
}
else if(num % 2 == 0 || num % 3 ==0){
return false;
}
else{
//Note that any primes greater than 2 or 3 can be expressed in the form 6k+1 of 6k - 1.
for(int i = 5; i <= Math.sqrt(num);i+=6){
//Check if num is divisible by 6k + 1 or 6k - 1.
if(num % i == 0 || num % (i + 2) == 0){
return false;
}
}
return true;
}
}
public static void main(String[] args) {
long sumPrimes = 1709600813;
for(int i = 200000; i < 2000000; i++){
if(isPrime(i)){
sumPrimes += i;
}
}
System.out.println(sumPrimes);
}
}