Help with MAGICMED - QFUN2020

problem link.

this cpp code failed at subtask two.
while this python code passed.

i know it has something to do with interger value overflow but i can’t figure out where is it oveflowing?

Couple of things that are incorrect in the cpp solution .
First is that you should not be using b%MOD, c%MOD while calling the power function.
Next is that the final value is to be taken modulo 10^8+7 while you have taken the final value modulo 10^9+7.
Here is a link to your code which gives a full AC.

1 Like


why is pow(a , b) different than pow(a % MOD, b % MOD)? they should yeild same result shouldn’t they?

Why would they be same? You can take any example to show they’re different. say when b=mod.

1 Like

yes got it thanks. i am not good at maths.
but if this is a true property of modular arithmetics : (a x b) mod m = ((a mod m) x (b mod m)) mod m
i thought it would be same for modular exponentiation.

Consider a=b=mod and then say. The second expression of yours will become inderminate.

1 Like

yes got it. thankyou so much :grin:

1 Like