// The "Prime" class.
import java.awt.*;
import hsa.Console;
import java.lang.Math;
import java.net.*;

public class Prime
{
    static Console c;           // The output console

    public static void main (String[] args)
    {
	c = new Console ();
	int limit, k, n, x, y;
	int cnt = 2;
	limit = 1000;         // arbitrary search limit
	boolean[] is_prime = new boolean [limit + 1];

	for (n = 5 ; n <= limit ; n++)
	{
	    is_prime [n] = false;  // initialize the sieve
	}

	// put in candidate primes:
	// integers which have an odd number of representations by certain quadratic forms
	for (x = 1 ; x <= Math.sqrt (limit) ; x++)
	{
	    for (y = 1 ; y <= Math.sqrt (limit) ; y++)
	    {
		n = 4 * x * x + y * y;
		if (n <= limit & (n % 12 == 1 || n % 12 == 5))
		    is_prime [n] = !(is_prime [n]);
		n = 3 * (x * x) + y * y;
		if (n <= limit & n % 12 == 7)
		    is_prime [n] = !(is_prime [n]);
		n = 3 * (x * x) - y * y;
		if (x > y & n <= limit & n % 12 == 11)
		    is_prime [n] = !(is_prime [n]);
	    }
	}
	// eliminate composites by sieving
	for (n = 5 ; n <= Math.sqrt (limit) ; n++)
	{
	    if (is_prime [n])
	    {
		// n is prime, omit multiples of its square; this is sufficient because
		// composites which managed to get on the list cannot be square-free
		for (k = n * n ; k <= limit ; k += n * n)
		{
		    is_prime [k] = false;
		}
	    }
	}

	c.print ("2 3 ");
	for (n = 5 ; n <= limit ; n++)
	{
	    if (is_prime [n])
	    {
		c.print (n + " ");
		cnt++;
	    }
	    // Place your program here.  'c' is the output console
	} // main method

	c.print ("\nCount = " + cnt);
    } // Prime class
}
