Sum
Time Limit: 1000msMemory Limit: 131072KBThis problem will be judged on HDU. Original ID: 4704
64-bit integer IO format: %I64d Java class name: Main
Prev Submit Status Statistics Next
Type:
None
Tag it!
Sample Input
2
Sample Output
2
这个就是找一个数的划分,比如 3有以下几种情况
3
1 2
2 1
1 1 1
规律求2 ^(n-1)
然后介绍 费马小定理
a的p次方,p为素数,且a,p互质,就有 a^(p-1)=p;
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
typedef long long ll;
using namespace std;
const ll N=(ll)1e9+7;
ll quick_sort(ll a,ll b)
{
ll s=1;
while(b)
{
if(b&1)
s=s*a%N;
a=a*a%N;
b=b>>1;
}
return s%N;
}
char str[(int)1e5+10];
int main()
{
// printf("%lld\n",N);
while(~scanf("%s",str))
{
ll num=0,ans=0;
for(int i=0;i<strlen(str);i++)//大数取模
num=(num*10+(str[i]-'0'))%(N-1);
if(!num)
{
// puts("1");
ans=quick_sort(2,N-2);
}
else
ans=quick_sort(2,num-1);
printf("%lld\n",ans);
}
return 0;
}