Pls help me to debug


corrected!!
look at your corrected code!!
you should take modulo while exponentiation, not after everything is over, it might incur overflow!!

hit a like button if it works fine!!

@Senjuti256 is your doubt clear if yes just mark it resolved

No my doubt is not cleared.Why are we taking mod n while we are multiplying the powers of a in each iteration?

@Senjuti256 because when we take mod we have to take at every step
like if we keep multiplying a then value can become too long to be stored in any variable thats why we mod to make it small

so in all such questions where we will be asked to take Mod should we take Mod in every step?

yes!!
you should…
…