28 lines
440 B
Python
Executable File
28 lines
440 B
Python
Executable File
#!/usr/bin/env python3
|
|
# 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, int(testMax), 2):
|
|
isPrime = cnt % test
|
|
if isPrime == 0:
|
|
break
|
|
|
|
if isPrime != 0 :
|
|
print(cnt)
|
|
|