- Description
给定整数a,b,n,要求计算(a^b)mod n
- Input
多组数据,每组数据一行,为三个用空格隔开的整数a,b,n
1<=a<=5000,0<=b<=10^8,1<=n<=5000000
- Output
每组数据输出一行,为所求值
- Sample Input
2 3 5
2 2 4
- Sample Output
3
0
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
__int64 a,b,c;
void solve()
{
__int64 res=1;
while(b)
{
if(b&1) res=res*a%c;
a=a*a%c;
b>>=1;
}
printf("%I64d\n",res);
}
int main()
{
while(scanf("%I64d %I64d %I64d",&a,&b,&c)!=EOF)
{
solve();
}
return 0;
}