thopecoder's blog

By thopecoder, history, 4 years ago, In English

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?

Full text and comments »

  • Vote: I like it
  • +6
  • Vote: I do not like it