The proof as given in " David M. Burton " is as follows:
Suppose that $a^n \equiv a \pmod n$ for every integer a, but $k^2\mid n$ for some $k > 1.$ If we let $a = k,$ then $k^{n} \equiv k \pmod n.$ Because $k^2\mid n$, this last congruence holds modulo $k^2$; that is $ k \equiv k^{n} \equiv 0 \pmod {k^2}$, whence $k^2\mid k$, which is impossible. Thus, $n$ must be square-free.
But I do not understand this statement :
"this last congruence holds modulo $k^2$; that is $ k \equiv k^{n} \equiv 0\pmod {k^2}$"
Could anyone explain it for me please? why this last congruence holds modulo $k^2$ ? and why this leads to that $ k^{n} \equiv 0$?
Here's my steps.
Hopefully you can get it in polynomial form. All I used was: conversion of modular congruence to a linear polynomial, divisor pairing, substitution, and factoring out ( reverse of distribution). The portion you quote breaks down to: $$k^n\equiv 0\bmod k^2$$ and, $$k\equiv k^n\bmod k^2$$ The latter of which follows from $k^2$ being a divisor of n, the former from $n>1$