#include<stdio.h> #include<string.h> long bigmod(long b,long p,long m); long square(long x); int main() { long b,p,m,i,j,k,l; while(scanf("%ld %ld %ld",&b,&p,&m)==3) { printf("%ld\n",bigmod(b,p,m)); } return 0; } long bigmod(long b,long p,long m) { if (p == 0) return 1; else if (p%2 == 0) return square(bigmod(b,p/2,m)) % m; else return ((b % m) * bigmod(b,p-1,m)) % m; } long square(long x) { return (x*x); }
No comments:
Post a Comment