Solve problem 131.
This commit is contained in:
29
python/e131.py
Normal file
29
python/e131.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
from lib_prime import primes
|
||||||
|
|
||||||
|
|
||||||
|
def is_cube(n):
|
||||||
|
if n == 0:
|
||||||
|
return False
|
||||||
|
return round(n ** (1/3)) ** 3 == n
|
||||||
|
|
||||||
|
|
||||||
|
def euler_131():
|
||||||
|
r = 0
|
||||||
|
ps = primes(10**6)
|
||||||
|
minm = 1
|
||||||
|
for p in ps:
|
||||||
|
for m in range(minm, minm + 20):
|
||||||
|
n = m * m * m
|
||||||
|
x = n * n * n + n * n * p
|
||||||
|
if is_cube(x):
|
||||||
|
# print(p, n)
|
||||||
|
r += 1
|
||||||
|
minm = m
|
||||||
|
break
|
||||||
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
solution = euler_131()
|
||||||
|
print("e131.py: " + str(solution))
|
||||||
|
assert(solution == 173)
|
||||||
Reference in New Issue
Block a user