HDU 4990 Reading comprehension

快速幂

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std; long long n,MOD; long long cal(long long a,long long b,long long mod)
{
long long c=;
while(b!=)
{
if(b%==) c=(c*a)%mod,b--;
else a=(a*a)%mod,b=b/;
}
return c;
} int main()
{
while(cin>>n>>MOD)
{
if(n%==)
cout<<(cal(,n+,MOD*)-)/<<endl;
else
cout<<(cal(,n+,MOD*)-)/<<endl;
}
return ;
}
上一篇:HDU 4990 Reading comprehension 矩阵快速幂


下一篇:HDU - 4990 Reading comprehension 【矩阵快速幂】