Skip to content

Instantly share code, notes, and snippets.

@your-diary
Last active July 18, 2021 06:08
Show Gist options
  • Save your-diary/b1ce8e464152b3e092d327c31f132b36 to your computer and use it in GitHub Desktop.
Save your-diary/b1ce8e464152b3e092d327c31f132b36 to your computer and use it in GitHub Desktop.
Exhaustive search to find the solution for `i^5 + j^5 + k^5 + l^5 = z^5`, known as Euler's conjecture.
#!/usr/bin/env python3
#Exhaustive search to find the solution for `i^5 + j^5 + k^5 + l^5 = z^5`, known as Euler's conjecture.
#According to |https://www.math.uci.edu/~brusso/stewart230-231.pdf|, one of the solution is first found in 1966 by exhaustive search.
#Complexity (real, M1 mac): 2.57e-07 * n^3
import math
import sys
import time
n: int = 0
while (True):
start: int = time.time()
n += 1
print(n, end = ' ')
for i in range(1, n + 1):
for j in range(i, n + 1):
for k in range(j, n + 1):
l: int = n
r: int = i**5 + j**5 + k**5 + l**5
p: int = math.floor(r**(1 / 5))
q: int = math.ceil(r**(1 / 5))
if ((p**5 == r) or (q**5 == r)):
if (q**5 == r):
p = q
print(f'[Solved! {i}^5 + {j}^5 + {k}^5 + {l}^5 = {p}^5]')
sys.exit(0)
print(time.time() - start)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment