48 lines
905 B
Python
48 lines
905 B
Python
from timer import timing_function
|
|
|
|
|
|
def isprime(number, primelist):
|
|
"""
|
|
checks if a number is prime by finding dividing it by every other prime
|
|
below floor(number / 2)
|
|
"""
|
|
for prime in primelist:
|
|
if prime <= number // 2 and number % prime == 0:
|
|
return False
|
|
|
|
return True
|
|
|
|
@timing_function
|
|
def findprimesto(primecap):
|
|
"""
|
|
finds numprimes count of prime numbers
|
|
"""
|
|
primelist = [2]
|
|
testnum = 3
|
|
|
|
while testnum < primecap:
|
|
|
|
if isprime(testnum, primelist):
|
|
primelist.append(testnum)
|
|
|
|
testnum += 2
|
|
|
|
return primelist
|
|
|
|
@timing_function
|
|
def findxprimes(x):
|
|
"""
|
|
finds numprimes count of prime numbers
|
|
"""
|
|
primelist = [2]
|
|
testnum = 3
|
|
|
|
while len(primelist) < x:
|
|
|
|
if isprime(testnum, primelist):
|
|
primelist.append(testnum)
|
|
|
|
testnum += 2
|
|
|
|
return primelist
|