Problem 10 of Find the sum of all the primes below two million.
2012-03-13 11:49
525 查看
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
Find the sum of all the primes below two million.
public class BigPrime { public static void main(String args[]){ long j=0; for(long i=2;i<2000000;i++){ if(isPrime(i)){ j+=i; } } System.out.println(j); } public static boolean isPrime(long n){ for(int i = 2; i * i <= n; i++){ if(n % i == 0) return false; } return true; } }
Answer: | 142913828922 |
相关文章推荐
- Problem 1:Find the sum of all the multiples of 3 or 5 below 1000.
- Problem 21 of Evaluate the sum of all the amicable numbers under 10000.
- geeksforgeeks Find the maximum path sum between two leaves of a binary tree
- hdu 1231, dp ,maximum consecutive sum of integers, find the boundaries, possibly all negative, C++
- Find the first intersection of two lists (if the two list are merged at some point)
- find the two same numbers in 1 million random numbers
- Genymotion提示To find out the cause of the problem,start the virtual device from VirtualBox
- To find the list of all the available drives on...
- To find sum of two numbers without using any operator. Only use of printf() is allowed.
- find the smallest subtree that contains all of the tree's deepest nodes
- Find all the permutations of a string
- I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum o
- geeksforgeeks@ Find sum of different corresponding bits for all pairs (Bit manipulation)
- The Secret To 10 Million Concurrent Connections -The Kernel Is The Problem, Not The Solution
- project euler problem 10:Summation of primes
- Find the median of two sorted arrays(找到两个排好序的数组的中位数)
- Spatial index is slow when trying to find all the points within a range of a geocode.
- The Secret To 10 Million Concurrent Connections -The Kernel Is The Problem, Not The Solution
- Given a sequence of numbers (or array).Find the maximum distance between all the same numbers.
- Find the nearest common ancestor of any two nodes in a binary search tree