import element.*;

public class sieve2 extends Thread
{
    private static final int max = 10000;
    private int fact;
    private sieve nextFilter;

    public Semaphore modifyInput;
    private int input;

    public sieve()
    {
        inputValid = false;
        modifyInput = new Semaphore();
        
    }

    synchronized public int read()
    {
        int result = input;
        inputValid = false;
        notify();
        return result;
    }

    synchronized public void write(int n)
    {
        while (inputValid)
        {
            try
            {
                wait();
            } catch (Exception e) {}
        }
        input = n;
        inputValid = true;
        notify();
    }

    public void run()
    {
        fact = read();
        System.out.println(fact);
        int n;
        nextFilter = new sieve();
        nextFilter.setPriority(Thread.NORM_PRIORITY-1);
        nextFilter.start();
        for (n = read(); n < max; n = read())
        {
            if (0 == n % fact) continue;
            nextFilter.write(n);
        }
    }

    public static void main(String args[])
    {
        sieve source = new sieve();
        source.setPriority(Thread.NORM_PRIORITY-1);
        source.start();
        int i;
        for (i = 2; i < max; i++)
        {
            source.write(i);
        }
    }
}
