Problem Description
Sample Input
2
Sample Output
2Hint1. For N = 2, S(1) = S(2) = 1. 2. The input file consists of multiple test cases.
推导:2^n%m == ( 2^(n%(m-1))*2^(n/(m-1)*(m-1)) )%m==(2^(n%(m-1)))%m;
#include<cstdio>
#include<cstring>
#define max_n 1000010
#define mod 1000000007
typedef long long ll;
char str[max_n];
ll quickpow(ll a,ll b,ll c)
{
ll ans=1;
while(b)
{
if(b&1)
ans=ans*a%c;
a=a*a%c;
b>>=1;
}
return ans;
}
int main()
{
while(~scanf("%s",str))
{
ll len=strlen(str);
ll ans=0;
for(ll i=0;i<len;i++)
ans=(ans*10+str[i]-'0')%(mod-1);
ans=(ans-1+mod-1)%(mod-1);
printf("%lld\n",quickpow(2,ans,mod));
}
return 0;
}