34 lines
706 B
Python
34 lines
706 B
Python
|
from lib_prime import get_divisors_count
|
||
|
|
||
|
|
||
|
def euler_179_orig():
|
||
|
r = 0
|
||
|
for n in range(2, 10**7):
|
||
|
if n % 10**5 == 0:
|
||
|
print(n)
|
||
|
if get_divisors_count(n) == get_divisors_count(n + 1):
|
||
|
r += 1
|
||
|
return r
|
||
|
|
||
|
|
||
|
def euler_179():
|
||
|
""" Much faster version. """
|
||
|
upper = 10**7
|
||
|
ndivs = [1 for _ in range(0, upper + 2)]
|
||
|
for d in range(2, upper // 2):
|
||
|
for i in range(d, upper + 2, d):
|
||
|
ndivs[i] += 1
|
||
|
|
||
|
r = 0
|
||
|
for i in range(2, upper + 1):
|
||
|
if ndivs[i] == ndivs[i + 1]:
|
||
|
r += 1
|
||
|
return r
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
solution = euler_179()
|
||
|
print("e179.py: " + str(solution))
|
||
|
assert(solution == 986262)
|
||
|
|