给出3个正整数A B C,求A^B Mod C。
例如,3 5 8,3^5 Mod 8 = 3。
Input
3个正整数A B C,中间用空格分隔。(1 <= A,B,C <= 10^9)
Output
输出计算结果
Input示例
3 5 8
Output示例
3
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
ll mod_pow(ll x,ll n,ll mod)
{
ll res=1;
while(n>0) {
if(n&1) res=res*x%mod;
x=x*x%mod;
n>>=1;
}
return res;
}
int main()
{
int a,n,mod;
cin>>a>>n>>mod;
cout<<mod_pow(a,n,mod)<<endl;
return 0;
}