(String args[])
| 3 | |
| 4 | public class sieve { |
| 5 | public static void main(String args[]) { |
| 6 | int NUM = Integer.parseInt(args[0]); |
| 7 | boolean [] flags = new boolean[8192 + 1]; |
| 8 | int count = 0; |
| 9 | while (NUM-- > 0) { |
| 10 | count = 0; |
| 11 | for (int i=2; i <= 8192; i++) { |
| 12 | flags[i] = true; |
| 13 | } |
| 14 | for (int i=2; i <= 8192; i++) { |
| 15 | if (flags[i]) { |
| 16 | // remove all multiples of prime: i |
| 17 | for (int k=i+i; k <= 8192; k+=i) { |
| 18 | flags[k] = false; |
| 19 | } |
| 20 | count++; |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | System.out.print("Count: " + count + "\n"); |
| 25 | } |
| 26 | } |
| 27 |