Untitled
By: a guest | Feb 9th, 2010 | Syntax:
Java | Size: 0.53 KB | Hits: 158 | Expires: Never
//Find the sum of all the primes below two million.
package problem10;
public class Problem10 {
public static void main
(String[] args
) {
long sum = 0;
for (long i = 0; i < 2000000; i++) {
if (isPrime(i)) {
sum += i;
}
if (i % 10000 == 0) {
}
}
}
public static boolean isPrime(long n) {
long i = 2;
while (i < n) {
if (n % i == 0) {
return false;
}
i++;
}
return true;
}
}
//142913828923
//9223372036854775808