Add prime generator function
This commit is contained in:
@@ -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)
|
||||||
#
|
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
Reference in New Issue
Block a user