vignesh_in_zone's blog

By vignesh_in_zone, history, 6 weeks ago, In English

given three numbers p , q, r calculate the pow( p , q!) % r

It would also be helpful if you could mention the important concepts needed in solving this problem ,

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
6 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

If $$$p$$$ and $$$r$$$ are relatively prime you use Euler's theorem $$$p^{\phi(r)} = 1$$$ mod $$$r$$$. So you need to calculate $$$q!$$$ mod $$$\phi(r)$$$. $$$\phi$$$ is the Euler totient function, for a prime $$$r$$$ it is just $$$r-1$$$. You can find the answer even if $$$(p, r) > 1$$$, but it involves additional steps.