Modular arithmetic

Please help how to solve this question

@neelmani98,

(a * b * c) % m = ((((a % m) * (b % m)) % m) * ( c % m )) % m)

Now try to think of (a ^ 3) % m which is (a * a * a) % m
Analogously think for power = b.

oh yeah got it thanku so much by mistake i assued it XOR

i changed the code to fine the power and still getting error i have saved the code in this link please refer it https://ide.codingblocks.com/s/197655

@neelmani98,
You are first calculating (a^b) then taking its mod. But (a^b) at worst case is too large to fit in long long also. So you need to take mod in every step of multiplication.

Try this,

ans=((ans%c)*(a%c))%c;

and,

a=((a&c)*(a%c))%c;