I am unable to find what is wrong with my code can anyone help me

My solution : https://www.codechef.com/viewsolution/33142871

It outputs the wrong answer on the sample… did you even test it?

I am not understanding why the logic is not working I tried to to the same using a calculator for the sample I am getting the ans given but I am not getting in code.

I think I am doing a mistake in taking mod or calculating power…

Yes, your answer for the sample is larger than the mod, that should tell you something.

a%=mod is this the change I should do before doing toReturn*=a

You tell me. Does it work?

No. I am still unable to get. can u give a clue that is the issue is in the power function or in cal ans

Look for yourself. At what point does your code’s values differ from what you expect them to be?

And also, how do you think your code’s output could possibly be bigger than 10^9 + 7? Your final answer is `ans % mod`

.