Math day Problem

my code failed to pass the last two cases.
please check into it

Take mod everywhere, like while squaring a and res=res%m;
You can check out this code too.

It still fails for the last two cases …please check it here https://ide.codingblocks.com/s/325956

Take a=a%m in the power function and it’ll work.
I’ve made changes in your code, you can check it here .

It is working now but why do we need to take mod of a too?

because a in test cases is more than m.