public static void main(String[] args) {
        int n = 2000000;
        long start = System.currentTimeMillis();
        BitSet b = new BitSet(n + 1);
        int count = 0;
        int i;
        
        // set all the bits
        for (i = 2; i <= n; i++) {
            b.set(i);
        }
        
        i = 2;
        while( i * i <= n) {
            if(b.get(i)) {
                //System.out.println( "\n" + i + ", ");
                count++;
                int k = 2 * i;
                while (k <= n) {
                    //System.out.print(k + ", ");
                    b.clear(k);
                    k += i;
                }
            }
            i++;
        }
        //System.out.println("\n=========");
        while(i <= n) {
            if(b.get(i)) {
               // System.out.println(i + ", ");
                count++;
            }
            i++;
        }

        long end = System.currentTimeMillis();
        System.out.println(count + " primes");
        System.out.println((end - start) + " milliseconds");
    }