find the value of (a^n!)%p

35 Views Asked by At

i can find the value by doing ((a^n)%p)^(n-1)!)%p but i am looking for a more easier/efficient way of doing it as a^n is pretty big.

PS this is my first question plzz pardon me if i am getting any protocol wrong

1

There are 1 best solutions below

3
On

HINT: Think about Fermat’s Little Theorem: If $p$ is prime and $p\nmid a$ then $$ a^{p-1}\equiv 1 \pmod{p} $$ So if $p-1|n!$ then $a^{n!}\equiv 1\pmod{p}$.