28 lines
431 B
Python
28 lines
431 B
Python
|
#!/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
|
||
|
for test in range(3, testMax, 2):
|
||
|
isPrime = cnt % test
|
||
|
if isPrime == 0:
|
||
|
break
|
||
|
|
||
|
if isPrime != 0 :
|
||
|
print cnt
|
||
|
|