#!/usr/bin/python

# Program to display primorials.
# Uses the programs "matho-primes" and "./multiply".

import os
import sys

def usage():
	print >>sys.stderr, "This program calculates large primorials."
	print >>sys.stderr
	print >>sys.stderr, "Usage: %s integers" % os.path.basename(sys.argv[0])
	print >>sys.stderr
	print >>sys.stderr, "Primorials are the product of all primes up to a given number."
	sys.exit(2)

args = sys.argv[1:]
if (args == []):
	usage()
else:
	for arg in args:
		try:
			if (int(arg) < 2):
				print >>sys.stderr, "Number too small."
				sys.exit(1)
		except:
			print >>sys.stderr, "Positive integer required."
			sys.exit(1)
		sys.stdout.write(arg + "# = ")
		sys.stdout.flush()
		if (os.system("matho-primes 0 " + arg + "|./multiply") != 0):
			sys.exit(1)
