The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
long result = 0; boolean[] gestrichen = new boolean[limit]; for (int i=2; i<gestrichen.length; i++) { gestrichen[i] = false; } for (int i=2; i<gestrichen.length; i++) { if (!gestrichen[i]) { System.out.println(i + " "); result += (long)i; for (int j=2*i; j<limit; j=j+i) { gestrichen[j] = true; } } } System.out.println("============="); System.out.println(result);
Lösung: 142913828922