mixster

mixster

Feb 26th, 2010
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 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[50000001];
  9.    
  10.     int limit = /*sqrt(50000000)*/ 7071;
  11.  
  12.         for(int i = 3; i <= limit; i += 2)
  13.             if(!composite[i])
  14.  
  15.             {
  16.  
  17.               for(int j = i * 2 + i; j <= 50000000; j += i * 2)
  18.           composite[j] = true;
  19.  
  20.             }
  21.  
  22.     final long endTime = System.nanoTime();
  23.  
  24.     for(int i = 3; i <= 50/*000000*/; i += 2)
  25.       if (!composite[i])
  26.         System.out.println(i);
  27.  
  28.     System.out.print(endTime - startTime);
  29.     System.out.println(" ns");
  30.     }
  31.    
  32. }
Add Comment
Please, Sign In to add comment