Disclaimer: not sure if it works
Based on OP's question, this question and its code, the comments on this post:
The idea is to compare very large numbers instead of numbers with very long decimal expansion, because pythons integers are unbounded.
First compute c = a**g + b**g
then s = int(c ** (1/g))
.
Now, if (a, b, s)
is a valid triplet of numbers, then either s**g
or (s+1)**g
would be equal to c
because:
- python's
int
function rounds down and
- triplets are comprised of integer numbers.
This way, we avoid directly comparing numbers with long decimal expansion by comparing very large numbers, which python can do.
Here's the code, similar to the referenced website:
def proof(n, g):
for a in range(1,n):
for b in range(a, n):
c = (pow(a, g) + pow(b, g))
s = int(c ** (1/g))
if (s**g == c):
print(f"{a},{b},{s}")
elif (s+1**g == c):
print(f"{a},{b},{s+1}")
proof(1000, 6)
There is a trivial error (1, 1, 2) because of s+1**g
, but other than that the code should work properly.
Please do check it yourself, I'm not very familiar with fermat's last theorem, something might have slipped by when coming up with a solution.