Add prime generator function

This commit is contained in:
2021-04-09 23:58:17 -04:00
parent b0cccc97ab
commit 01ce98cec6
2 changed files with 19 additions and 1 deletions

View File

@@ -27,4 +27,4 @@ if __name__ == "__main__":
solution = euler_087() solution = euler_087()
print("e087.py: " + str(solution)) print("e087.py: " + str(solution))
assert(solution == 1097343) assert(solution == 1097343)
#

View File

@@ -117,6 +117,24 @@ def primes(n_max):
return ps return ps
def gen_primes():
"""
Prime number generator function>
"""
primes = [2]
yield 2
p = 3
while True:
for i in primes:
if p % i == 0:
break
if i * i > p:
primes.append(p)
yield p
break
p += 2
def get_divisors_count(n): def get_divisors_count(n):
""" """
Returns the number of divisors for n. Returns the number of divisors for n.