1#!/usr/bin/python
2
3# This is a Python program to display large primorials.
4# A primorial is the product of all primes up to the given number.
5# Uses the programs "matho-primes" and "matho-mult" as follows:
6#	primorial 1000
7# runs:
8#	matho-primes 0 1000 | matho-mult
9#
10# For fun, try:
11#	primorial `matho-primes 2 97`
12#
13# to display all unique primorials from 2 to 97.
14
15import os
16import sys
17
18def usage(ev):
19	print "This program calculates large primorials."
20	print
21	print "Usage: %s integers" % os.path.basename(sys.argv[0])
22	print
23	print "A primorial is the product of all primes up to the given number."
24	sys.exit(ev)
25
26def output_primorial(arg):
27	sys.stdout.write(arg + "# = ")
28	sys.stdout.flush()
29	if (os.system("matho-primes 0 " + arg + " | matho-mult") != 0):
30		sys.exit(1)
31
32args = sys.argv[1:]
33if (args == []):
34	usage(2)
35else:
36	for arg in args:
37		try:
38			if (int(arg) < 1):
39				print >>sys.stderr, "Number too small."
40				sys.exit(1)
41		except:
42			print >>sys.stderr, "Positive integer required."
43			usage(1)
44		output_primorial(arg)
45