Math Day ( How to approach this )

Earlier i thought of fermats theorem then i realized that it holds for prime number , so sir may i can get a hint earlier i thought of solving it in nlogn but then it came out to be wrong bcz powers get added and it is multiplied i.e n*(n-1)*(n-2)…

You were right in thinking if doing it with fermet’s theorem. Try to convert it in the form of (prime+x),
apply fermet’s theorem for prime part and calculate for x using fast exponentiation.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.