fermat's last theorem by elementary methods I was wondering about correctness of the following theorem/proof.
Theorem:
Suppose $p$ is prime in:
$ \quad \quad p^k | x - y$
$ \quad \quad p^{k + 1} \not | x - y$
$ \quad \quad gcd(x,y,z) = 1$
$ \quad \quad n > 2$
$ \quad \quad x^n = y^n + z^n$ 
Then:
$ \quad \quad p | n$
Proof:
Let us consider the following identity:
$\quad \quad (ap^k + b)^n = b^n + rp^k \pmod {p^{2k}} \iff r = nab^{n - 1} \pmod {p^k}$
which we can prove by induction on $n$.
When we solve for $a,b$ in:
$ \quad \quad ap^k + b = x$,
$ \quad \quad b = y$,
we get: 
$ \quad \quad a = (x - y)/p^k \implies gcd(a,p) = 1$ because $x - y \not \equiv 0 \pmod {p^{k + 1}}$,
also note:
$ \quad \quad gcd(b,p) = 1$ otherwise we would have $gcd(x,y,z) \gt 1$;
We now have:
$ \quad \quad p^k$ a prime-power;
$ \quad \quad gcd(a,p) = gcd(b,p) = 1$;
Now assume $z$ exists in:
$ \quad \quad x^n \equiv y^n + z^n \pmod {p^{2k}} \iff (ap^k + b)^n \equiv b^n + rp^k \pmod {p^{2k}}$
$ \quad \quad \implies z^n \equiv rp^k \pmod {p^{2k}}$
We must consider the following three cases:


*

*$n \gt k \implies p | z \implies z = sp$ for some $s$


$ \quad \quad \implies z^n \equiv (sp)^n \equiv rp^k \pmod {p^{2k}}$
$ \quad \quad \implies s^np^{n - k} \equiv r \pmod {p^k}$
$ \quad \quad $ so clearly $p | r$


*$n = k \implies p | z \implies z = sp$ for some $s$


$ \quad \quad \implies z^n \equiv (sp)^n \equiv rp^n \pmod {p^{2n}}$
$ \quad \quad \implies s^n \equiv r \equiv nab^{n - 1} \pmod {p^n}$
$ \quad \quad $ Now let:
$ \quad \quad \quad \quad na \equiv b \pmod {p^n}$
$ \quad \quad \quad \quad \implies r \equiv nab^{n - 1} \equiv b^n \pmod {p^n}$
$ \quad \quad $ So we get:
$ \quad \quad \quad \quad (ap^n + b)^n \equiv b^n + (bp)^n \pmod {p^{2n}}$
$ \quad \quad \quad \quad \implies gcd(x,y,z) > 1$, which is impossible


*$n < k \implies p^t | z \implies z = sp^t$ for some $s$ and with $t = ceil(k/n)$


$ \quad \quad \implies z^n \equiv (sp^t)^n \equiv rp^k \pmod {p^{2k}}$
$ \quad \quad \implies s^np^{tn - k} \equiv r \pmod {p^n}$
$ \quad \quad$ and since $tn \gt k$ we have $p | r$
So we have shown $p | r \implies n \equiv 0 \pmod p$ always holds
Note that we cannot say anything about $n = 2$, because we always have:
$ \quad \quad (ap + b)^2 \equiv b^2 + z^2 = b^2 \pmod {p^2}$
$ \quad \quad \iff r \equiv 0 \pmod {p}$
no matter what $a,b$ will be
This proves our theorem.

Let $n$ be a positive integer, $n > 1$, and suppose $b,c,d$ are positive integers with $\gcd(b,c,d)=1$ such that $d^n = b^n + c^n$.

Next, suppose $p$ is a prime such that $d=ap+b$.
\begin{align*}
\text{Then}\;\;&(ap + b)^n = b^n + c^n\\[4pt]
\implies\;&p\mid c^n\\[4pt]
\implies\;&p\mid c\\[4pt]
\end{align*}
So you can't choose $p$ arbitrarily, since $p$ must be a factor of $c$.

What you proved is that if $p$ is a prime factor of $c$, then $p\mid a$ or $p\mid n$.

Stated in full, what you proved is equivalent to this:

\begin{align*}
&\text{If:}\\[4pt]
&\;\;{\small\bullet}\;\;\text{$n$ is a positive integer with $n > 1$}\\[4pt]
&\;\;{\small\bullet}\;\;\text{$b,c,d$ are positive integers with $\gcd(b,c,d)=1$}\\[-1pt]
&{\phantom{\;\;{\small{\bullet}}\;\;}}\text{such that $d^n = b^n + c^n$}\\[4pt]
&\;\;{\small\bullet}\;\;\text{$p$ is a prime factor of $c$}\\[8pt]
&\text{Then:}\\[4pt]
&\;\;{\small\bullet}\;\;\text{$p\mid n\;$ or $\;p^2 \mid (d-b)$}\\[4pt]
\end{align*}
