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