Recent Posts
PAWN | 1 min ago
None | 1 min ago
None | 1 min ago
Per | 2 min ago
None | 2 min ago
None | 2 min ago
T-SQL | 2 min ago
XML | 2 min ago
T-SQL | 2 min ago
None | 2 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Anonymous on the 10th of Feb 2010 12:11:09 AM Download | Raw | Embed | Report
  1. //Find the sum of all the primes below two million.
  2.  
  3. package problem10;
  4.  
  5. public class Problem10 {
  6.         public static void main(String[] args) {
  7.                 long sum = 0;
  8.                 for (long i = 0; i < 2000000; i++) {
  9.                         if (isPrime(i)) {
  10.                                 sum += i;
  11.                         }
  12.                         if (i % 10000 == 0) {
  13.                                 System.out.println(i);
  14.                         }
  15.                 }
  16.                 System.out.println(sum);
  17.         }
  18.        
  19.         public static boolean isPrime(long n) {
  20.                 long i = 2;
  21.                 while (i < n) {
  22.                         if (n % i == 0) {
  23.                                 return false;
  24.                         }
  25.                         i++;
  26.                 }
  27.                 return true;
  28.         }
  29. }
  30. //142913828923
  31. //9223372036854775808
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: