Solving an equation mod $n$

67 Views Asked by At

Part of a solution, I'm trying to calculate $(n-1)^2$ in $mod\ n$ when $n\in\mathbb{N}$. What I tried to do:

$$ (n-1)^2=(n^2-2n+1)\ (mod\ n)$$

But I'm not sure what to do next. How should I approach this?

2

There are 2 best solutions below

0
On

$n-1\equiv -1 \pmod n$

So $(n-1)^2 \equiv (-1)^2 \equiv 1\pmod n$.

....

Or $n^2= n*n \equiv 0 \pmod n$. And $-2n\equiv (-2)*n\equiv 0 \pmod n$. ANd $1 \equiv 1\pmod n$.

So $n^2 - 2n + 1 \equiv 0 + 0 + 1 \equiv 1 \pmod n$.

...

You just need to keep is mind for $a\equiv \alpha \pmod n$ and $b \equiv \beta \pmod n$

That $a \pm b\equiv \alpha \pm \beta \pmod n$ and $ab \equiv \alpha \beta \pmod n$ and $ma\equiv m\alpha \pmod n$ and $a^k \equiv \alpha^k \pmod n$ and that $n \equiv 0 \pmod n$.

EVERYTHING falls from that exceedingly nicely.

(In other words nearly all arithmetic distributes over modulus, and that $n$ is equivalent to $0$.)

(So $(n-1)^2$ is over modulus then, under $\mod n$ arithmetic, the same thing as $(-1)^2$.)

(A few things to watch out for. Division doesn't distribute unless divisor and modulus are relatively prime. And the powers of exponents are not actually arithmetic so they don't distribute.)

0
On

Since $${n^2}\equiv 0\pmod n$$ $$-2n\equiv 0\pmod n$$ You have $${(n-1)^2}\equiv ({n^2}-2n+1)\equiv 0+0+1\equiv1 \pmod n$$