39 lines
708 B
Python
39 lines
708 B
Python
from timer import timing_function
|
|
|
|
|
|
def isprime(number):
|
|
"""
|
|
checks if a number is prime by dividing it into every odd number less than
|
|
number // 2
|
|
"""
|
|
|
|
current_num = 3
|
|
|
|
if number % 2 == 0:
|
|
return False
|
|
|
|
while current_num <= number // 2:
|
|
if number % current_num == 0:
|
|
return False
|
|
current_num += 2
|
|
|
|
return True
|
|
|
|
@timing_function
|
|
def findprimesto(primecap):
|
|
for i in range(0, primecap):
|
|
isprime(i)
|
|
|
|
@timing_function
|
|
def findxprimes(x):
|
|
primelist = []
|
|
current_num = 2
|
|
|
|
while len(primelist) < x:
|
|
if isprime(current_num):
|
|
primelist.append(current_num)
|
|
|
|
current_num += 1
|
|
|
|
return primelist
|