Take That, Fermat!

You’ve certainly heard of Fermat’s last theorem stating that

$x^n+y^n=z^n$

has no integer solutions for $n\geqslant{3}$. Well, guess what:

$85751^{12} + 95642^{12} = 97565^{12}$.

Take that, Fermat!

Well, no. There’s a catch. The real solution is

$85751^{12} + 95642^{12} \approx 97565.000000006005409^{12}$.

It’s not a counter-example. It’s just very, very close to one. It’s almost an integer, a near miss, but not an all-integer solutions. On a pocket calculator—or even with a computer program like galculator—the expression

(85751^12 + 95642^12)^(1/12)

yields an integer value, 97565, while it shouldn’t. The rounding is merely an effect of limited precision, not so much of the internal floating point representation, than of the routine used to print the values. If you try to print 0.0000000001, you may get just 0.

*
* *

It’s rather easy to find these, if you’re in not much of a hurry. You can find them by brute-force:

```#!/usr/bin/env python

min_search=85000
max_search=100000
power=12

for a in xrange(min_search,max_search):
for b in xrange(a+1,max_search+1):
pa=a**power
pb=b**power
c=(pa+pb)**(1.0/power)
lc=long(c)
if c-lc<0.00000001:
print a,'^',power,'+',b,'^',power,'=',lc,'^',power
```

I used Python because it knows how to deal with large integers (while it’s rather complicated to do so in C++).

There is mostly likely a better way than exhaustive search to produce triplets, but brute force works properly. The above program takes a few seconds to produce its first triplet.