Fermat's Last Theorem states that for integers $p > 2$, there are are no natural numbers $a, b, c$ such that
$$a^p + b^p = c^p.$$Note that, for example, for $p=2$, there are such $a, b, c$ (e.g., $3^2+4^2=5^2.$
Let's write a program that tries to find a, b, and c, such that $a^p + b^p = c^p.$ The strategy is as follows: first, we'll try all possible a, b, and c in the range 1..1. Then we'll try all possible a, b, and c in the range 1..2. Then we'll try all possible a, b, and c in the range 1..3, and so on. If we find a solution at any point, we return.
def fermat(p):
n = 1
while True:
for i in range(1, n):
for j in range(1, n):
for k in range(1, n):
if i**p + j**p == k**p:
return i, j, k
n += 1
We can call fermat(2) to make sure that this works:
fermat(2)
According to Fermat's Last Theorem, fermat(p) will never return for p > 2. (So that we could claim that the complexity is infinity.) However, this is not at all obvious a priori (it took hundreds of years to figure out!)