Question: Calculate the remainder when p^(q!) is divided by r.

Revision en1, by thopecoder, 2020-08-12 15:14:02

Given three integers p,q,r. You have calculate remainder when $$$p^{(q!)}$$$ is divided by r. where '!' is factorial.

basically $$$p^{(q!)}$$$%r

constraints: 1 <= p,q,r <= 10^5

I have tried using naive factorization with binary exponentiation. Is there a more optimized approach for this problem?

Tags #modular exponentiation, factorization, #algorithms, #optimization

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English thopecoder 2020-08-12 15:14:02 363 Initial revision (published)