//  Data Structures with Java by John R. Hubbard
//  Copyright McGraw-Hill, 2001
//  Problem 2.22 on page 47
//  The Sieve of Eratosthenes

import java.util.Vector;

public class Pr0223
{ private static final int SIZE=1000;
  private static Vector sieve = new Vector(SIZE);

  public static void main(String[] args)
  { initializeSieve();
    printSieve();
  }

  private static void initializeSieve()
  { sieve.add(Boolean.FALSE);
    sieve.add(Boolean.FALSE);
    for (int i=2; i<SIZE; i++)
      sieve.add(Boolean.TRUE);
    for (int n=2; 2*n<SIZE; n++)
      if (((Boolean)sieve.get(n)).booleanValue())
        for (int m=n; m*n<SIZE; m++)
          sieve.set(m*n,Boolean.FALSE);
  }
  
  private static void printSieve()
  { int n=0;
    for (int i=0; i<SIZE; i++)
      if (((Boolean)sieve.get(i)).booleanValue())
        System.out.print((n++%10==0?"\n":"\t")+i);
    System.out.println("\n" + n + " primes less than " + SIZE);
  } 
}
