mixster

mixster

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