Problem 10
问题描述:
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
public static boolean IsPrime(long number) {int begin = 2;int end = (int) Math.sqrt(number) + 1;for (int i = begin; i < end; i++) {if (number % i == 0)return false;}return true;}public static long sum(){long result = 0;int begin = 2;int end = 2000000;for(int i=begin; i<end; i++){if(IsPrime(i)){result += i;}}return result;}