mixster

mixster

Feb 26th, 2010
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. public class primes
  2. {
  3.  
  4.     public static void main(String[] args) {
  5.         final long startTime = System.nanoTime();
  6.  
  7.         boolean[] composite = new boolean[25000001];
  8.  
  9.         int limit = /*sqrt(25000000)*/ 5000;
  10.  
  11.         for(int i = 2; i <= limit; i++)
  12.             if(!composite[i]) {
  13.                 int o = i * 2 - 1;
  14.  
  15.                 for(int j = i + o; j <= 25000000; j += o)
  16.                     composite[j] = true;
  17.  
  18.             }
  19.  
  20.         final long endTime = System.nanoTime();
  21.  
  22.         for(int i = 2; i <= 25/*000000*/; i += 1)
  23.             if (!composite[i])
  24.                 System.out.println(2 * i - 1);
  25.  
  26.         System.out.print(endTime - startTime);
  27.         System.out.println(" ns");
  28.     }
  29.  
  30. }
Add Comment
Please, Sign In to add comment