Sum
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 5322 Accepted Submission(s): 2099
Problem Description
Sample Input
2
Sample Output
2
Hint
-
For N = 2, S(1) = S(2) = 1.
-
The input file consists of multiple test cases.
Source
2013 Multi-University Training Contest 10
费马小定理/快速幂运算
https://blog.csdn.net/codeswarrior/article/details/79867198
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
char r[100010];
long long qpow(long long x,long long k)
{
long long ans=1,res=x;
while(k)
{
if(k&1) ans=(ans*res)%mod;
k>>=1;
res=res*res%mod;
}
return ans;
}
int main(){
long long n;
while(~scanf("%s",r))
{ n=0;
for(int i=0;i<strlen(r);i++)
{
n=(n*10+r[i]-'0')%(mod-1);
}
long long ans=qpow(2,n-1);
printf("%lld\n",ans);
}
}