题意:
将N拆分成1~n个数,问有多少种组成方法,
由隔板原理可知,n个数可以看成有n块板,n-1个间隔,每一个间隔可以有或者没有,那么有2^n-1中分法
重要的是题目中的n很大,到10^1000000,这让我们无法用矩阵快速幂计算
费马小定理:如果a和p互质,那么a^(p-1) %p = 1;
那么设temp = n%(p-1), 我们只要求2^temp%MOD即可
题目代码:
#include<bits/stdc++.h>
using namespace std;
const long long MAX = 1e9 + 7;
char s[1000010];
long long pow1(long long a, long long b)
{
long long temp, ans;
temp = a;
ans = 1;
// cout<<1111111<<endl;
while(b)
{
// cout<<ans<<endl;
if(b & 1)
{
ans *= temp;
ans %= MAX;
}
temp *= temp;
temp %= MAX;
b >>= 1;
}
// cout<<ans<<endl;
return ans;
}
int main()
{
while(scanf("%s", s) != EOF)
{
long long n = 0;
int len = strlen(s);
for(int i = 0; i < len; i++)
{
// cout<<i<<" "<<n<<endl;
n = (n*10 + s[i] - '0')%(MAX-1);
}
if(n == 0)
n = MAX-1;
//cout<<n<<endl;
long long ans = pow1(2, n-1);
cout<<ans<<endl;
}
return 0;
}