Untitled
raw download clone
TEXT
views 24
,
size 634 b
#include <stdio.h>

long long int x,y,m;
long long int ans,res;

long long int fpw(long long int x, long long int y, long long int m){
    if (y==0) res=1% m;
    else{

        if (y % 2 == 0){
            res = fpw(x,y/2,m);
            res = res*res%m;
        }
        if (y % 2 == 1){
            res = fpw(x,y/2,m);
            if (x>m){
                res = res*res%m;
                res=(res%m)*(x%m)%m;
            }
            else{res = res*res*x%m;}
        }
    }
    return res;
}

int main(void){
    scanf("%lld%lld%lld",&x,&y,&m);
    printf("%lld\n", fpw(x,y,m));
    return 0 ;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.