2011-03-08 07:01:27 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Python version of a Prime Number Finder
|
|
|
|
# haplo@mindstab.net
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import math
|
|
|
|
|
|
|
|
try: max = int(sys.argv[1]);
|
|
|
|
except:
|
|
|
|
print "primes.py <MAX NUM>"
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
if max < 1:
|
|
|
|
print "Invalide MAX NUM"
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
for cnt in range(3, max, 2) :
|
|
|
|
testMax = math.sqrt(cnt)+1
|
|
|
|
isPrime = 1
|
2013-01-31 04:47:41 +00:00
|
|
|
for test in range(3, int(testMax), 2):
|
2011-03-08 07:01:27 +00:00
|
|
|
isPrime = cnt % test
|
|
|
|
if isPrime == 0:
|
|
|
|
break
|
|
|
|
|
|
|
|
if isPrime != 0 :
|
|
|
|
print cnt
|
|
|
|
|