Aim: To calculate (a^b)mod c
Here is the link of my code: https://ide.codingblocks.com/s/55433
I m getting wrong answer for 60% of the test cases, but am unable to figure out the error in the code.
Modular Exponentiation (Number Theory Challenge)
In the power_calc function whenever you are calculating res or x using multiplication
there you need to write
res=(res * x)%c;
x=(x * x)%c
otherwise they will overflow from long long int range.
Hit like if u get it
2 Likes
Can you please explain why we are taking mod at every step? i know the property (ab)%m = ((a%m)(b%m))%m .
But i am not able to relate this mod multiple property to the provided code. i dont want to mug up the code