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
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
Copyright © 2021 JogjaFile Inc.
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}$.