题目看了很久没看懂
就是给你数n,一种函数S(k),S(k)代表把数n拆成k个数的不同方案数,注意如n=3,S(2)是算2种的,最后让你求S(1~n)的和模1e9+7,n<=1e100000。那么其实一个S(k)就是把n个小球放到k-1个盒子里的种类数,求和也就是求个$2^{n-1}$。
n超大,但是模数只有1e9+7,用欧拉定理就行了。
/** @Date : 2017-09-12 18:41:59
* @FileName: HDU 4704 欧拉定理 降幂.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;
const LL mod = 1e9 + 7;
const LL phi = 1e9 + 6;
char a[N];
LL fpow(LL a, LL n)
{
LL res = 1;
while(n)
{
if(n & 1)
res = (res * a % mod + mod) % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main()
{
while(~scanf("%s", a))
{
LL n = 0;
for(int i = 0; i < strlen(a); i++)
{
n = ((n * 10LL) % phi + (LL)(a[i] - '0') ) % phi;
}
n = (n - 1 + phi) % phi;
while(n < 0)
n += phi;
LL ans = fpow(2, n % phi + phi);
printf("%lld\n", ans);
}
return 0;
}