Relation between powers of inverse modulo n.

278 Views Asked by At

Recently, I was studying enchanced euclidean algorithm. I am wondering if there is some way to calculate inverse of $a^2$ (and higher powers) modulo $n$, knowing inverse of $a$ modulo $n$. For example: inverse of $89$ modulo $10^9 +7$ is $415730340$. Can I calculate $89^2$ modulo $10^9 + 7$ without running euclidean algorithm again? What I am specifically asking is: Is it possible for a computer to calculate inverse of $89^K$ modulo $10^9 + 7$, where $K$ is a very big number, like $10^{10}$ in other way than first calculating $89^K$ and then running euclidean algorithm on it?

Calculating it in a brute-force way is not a problem for modern computers, but it would require coding own arithemtics, while I would like to calculate it using 64-bit integers only.

1

There are 1 best solutions below

0
On BEST ANSWER

If you know that the inverse of $a$ is $b$, then $ab\equiv 1\pmod{n}$. It turns out that the inverse of $a^2$ is just $b^2$, i.e $$a^2b^2=a(ab)b\equiv a(1)b=ab\equiv 1\pmod{n}$$ Similarly, the inverse of $a^K$ is just $b^K$.

Now if you want to calculate a large exponential of a a number, modulo $n$, there are fast ways to do this. The number of steps is approximately the log of the exponent.