#!/usr/bin/python

# Implementation of the Sieve of Eratosthenes, output in inverse order

import sys

# guard
if len(sys.argv) != 2:
  print "Syntax: "+sys.argv[0]+" max"
  sys.exit(1)

# vars
max = int(sys.argv[1])
data = [1]*(max+1)
results = [1]*0

print "Primes below "+str(max)+":"

# algorithm
for x in range(2,max+1):
  if data[x]:
    results.append(str(x))
    i = x+x
    while i <= max:
      data[i] = 0
      i += x

# result presentation
while len(results) > 0:
  print results.pop()
