[ create a new paste ] login | about

Link: http://codepad.org/UYt93mnb    [ raw code | output | fork ]

C, pasted on Jun 30:
#include <stdio.h>
long long int f(long long int x, long long int y, long long int m);

int main (void)
{
    long long int x, y, m, result;
    scanf("%lld%lld%lld", &x,&y,&m);
    result= f(x, y, m);
    printf("%lld\n", result);
}

long long int f(long long int x, long long int y, long long int m)
{
    if(y==0)
    {
       return 1%m;
    }

    if (y==2)
    {
        long long int ans = ( (x%m) * (x%m) )%m;
        //printf("%lld\n",ans);
        return ans;
    }

    if (y%2==1)
    {
        return ((x%m) * (f(x, y-1, m)%m))%m ;
    }

    else if (y>2)
    {
        long long int temp= f(x, y/2, m)%m;
        return ( temp * temp ) %m;
    }

}


Output:
1
2
3
602871319330735040

Exited: ExitFailure 19


Create a new paste based on this one


Comments: