## Fermat’s Last Theorem states that no three positive integers $a$, $b$, $c$ satisfy the equation

$$a^n+b^n=c^n$$

for any integer value of $n$ greater than 2.

For this problem we are only considering the case $n=3$. For certain values of $p$, it is possible to solve the congruence equation:

$$a^3+b^3 \equiv c^3 \pmod{p}$$

For a prime $p$, we define $F(p)$ as the number of integer solutions to this equation for $1 \le a,b,c < p$.
You are given $F(5) = 12$ and $F(7) = 0$.
Find the sum of $F(p)$ over all primes $p$ less than $6\,000\,000$.

### The solution to this problem is conceptually straight-forward, albeit computationally intensive. The congruence relation $a^3+b^3\equiv c^3\mod p$ is equivalent to $a^3+b^3-c^3$ being an integer multiple of $p$. This equivalently means that if we leave out the “mod $p$,” $p$ can be factored out of the left-hand side.

By Fermat’s Last Theorem, we know that there are no nontrivial solutions to $a^n+b^n=c^n$ for $n\geq3$ in the integers, let alone modulo $p$. Thus, the only solutions to the equation are “trivial” in the sense that at least two of $a,b,c$ are equivalent modulo $p$ (i.e., they are congruent to each other mod p).

Any $a$, $b$, and $c$ that solve the equation for $p$ must therefore be in one of the following configurations:

1. $a=b=c$

2. $a=b\neq c$

3. $a\neq b=c$

Each configuration corresponds to a distinct set of triples $(a,b,c)$ mod $p$.

In configuration 1, there are $p-1$ possible values for $a=b=c$, namely the integers 1 to $p-1$.

In configuration 2, there are $(p-1)(p-2)$ possible triples because there are $p-1$ possible choices for $a=b$, and for each such choice, there are $p-2$ choices for $c$ that are not equivalent to $a=b$.

Similarly, in configuration 3, there are $(p-1)(p-2)$ possible triples.

Thus, for each prime $p$, we have

$$F(p)=(p-1)+(p-1)(p-2)+(p-1)(p-2)=3(p-1)(p-2).$$

We need to sum $F(p)$ over all primes $p<6,000,000$. By the prime number theorem, there are approximately $6,000,000/\ln(6,000,000)\approx395,000$ such primes, but this is definitely an overestimate, as it doesn't account for the fact that the distribution of primes thins out the further you go along the number line. In any case, it's clear that this sum is not feasible to compute by hand. This would require a computer to compute. A script written in a programming language like Python or C++ could do the job.

##### More Answers:

Optimal Card StackingConcatenation Coincidence

Powers of $1+\sqrt 7$