1.题目
Input
2
Output
2
Hint
-
For N = 2, S(1) = S(2) = 1.
-
The input file consists of multiple test cases.
Sample Input
2
Sample Output
2
2.代码
#include<iostream>
#include <stdio.h>
using namespace std;
char N[100005];
const int mod=1e9+7;
//费马小定理
long long PhiMa(char *N,int mod)
{
long long ans=0;
for(int i=0;N[i]!='\0';i++)
ans=(ans*10+N[i]-'0')%mod;
return ans;
}
//快速幂取余运算
long long FastPow(long long a,long long b)
{
long long ans=1;
while(b)
{
if(b&1)
ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
int main()
{
while(scanf("%s",N)!=EOF)
{
long long n=PhiMa(N,mod-1)-1;
printf("%d\n",FastPow(2,n));
}
return 0;
}