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?