#include<iostream>
#include<cstdio>using namespace std;
int PowerMod(long long a, long long b, long long c)
{
long long ans = 1;
a=a%c;
while(b>0)
{
if(b%2==1)
ans=(ans*a)%c;
b=b/2;
a=(a*a)%c;
}
return ans;
}
int main()
{
long long ans, a,b,m;
while(cin>>a>>b>>m)
{
ans=quickmod(a,b,m);
cout<<ans<<endl;
}
return 0;
}
幂两次取模
Description
计算2013^b^c mod 10000000
Input
两个整数 b>0 c>0<b,c<10000000)< body="">
Output
输出2013^b^c mod 10000000的结果
Sample Input
2012 2011
Sample Output
3307281
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int PowerMod(long long a, long long b, long long c) { long long ans = 1; a=a%c; while(b>0) { if(b%2==1) ans=(ans*a)%c; b=b/2; a=(a*a)%c; } return ans; } int main() { long long a,b,sum1,sum2; cin>>a>>b; sum1=PowerMod(2013,a,10000000); sum2=PowerMod(sum1,b,10000000); cout<<sum2<<endl; return 0; }