Question: If $P$ is a prime and $a^2 \equiv b^2 (mod \text{ P})$ then prove that $a \equiv b (mod \text{ P})$ or $a \equiv -b (mod \text{ P})$.
My attempt (which seems to be failing beautifully): Let $f(x)$ be a function such that $f(x) = x^2$. Now, because $f(a) \equiv f(b) (mod \text{ n})$ iff $a \equiv b (mod \text{ n})$.
Hence, if given that $a^2 \equiv b^2 (mod \text{ P})$, this means that $f(a) \equiv f(b) (mod \text{ P})$ or $f(a) \equiv f(-b) (mod \text{ P})$
Problem: But I don't get the requirement that $P$ needs to be prime, because the way I am proving can be generalized for any integer $P$. I have tried integer values and I get that my proof is wrong for general $P$, but I can't seem to wrap this idea in the proof