CCCPaste

BIG Mod

//WAP to calculate big modulo (mod m) value of a power(p) of a number(b)
#include
int big_mod(int b,int p,int m);
int main()
{
    int x,y,z,res;
    scanf("%d %d %d",&x,&y,&z);
    res=big_mod(x,y,z);
    if(y%2==1)
        res=(res*(x%z))%z;
    printf("%d\n",res);
    return 0;
}

int big_mod(int b,int p,int m)
{
    int q;
    if(p==0)
        return 1;
    else
    {
        q=big_mod(b,p/2,m);
        return ((q*q)%m);
    }
}