// from http://vanemden.wordpress.com/2011/01/15/another-scoop-by-dijkstra/
#include <cassert>
#include <cstdio>
#include <cstdlib>

typedef unsigned nat; // natural number

void prTable(nat p[], nat n) {
// Place the first n prime numbers in p[0..n-1]
// using Trial Division.
  nat k;
  int work_done = 0;
  assert(n > 1);
  p[0] = 2; p[1] = 3;
  k = 2;
  while (k < n) {
  // p[0..k-1] are first k primes
    nat cand = p[k-1]+2;
    nat j = 0;
    while (p[j]*p[j] <= cand) {
    // p[0..j] do not divide cand
      j++;
      if (cand%p[j] == 0) {
        j = 0; cand += 2;
      }
      work_done += 2;           // one multiply, one divide
    }
    p[k++] = cand;
  }
  // p[0..k-1] are first k primes
  // k == n
  fprintf(stderr, "Did %d multiplies and divides\n", work_done);
}

int main(int arc, char **argv) {
  nat nn = atoi(argv[1]);
  nat *table = new nat[nn];
  prTable(table, nn);

  for (int ii = 0; ii < nn; ii++) {
    printf("%d\n", table[ii]);
  }

  return 0;
}

