There are N children in kindergarten. Miss Li bought them N candies. To make the process more interesting, Miss Li comes up with the rule: All the children line up according to their student number (1...N), and each time a child is invited, Miss Li randomly gives him some candies (at least one). The process goes on until there is no candy. Miss Li wants to know how many possible different distribution results are there.
Input
The first line contains an integer T, the number of test case.
The next T lines, each contains an integer N.
1≤T≤100
1≤N≤10100000
Output
For each test case output the number of possible results (mod 1000000007).
样例输入复制
1 4
样例输出复制
8
题目来源
解析:转化变成组合数学;
将n分成不超过n段(1~n)。
隔板法:在n里面选0~n-1的空隙。C(n-1,0)+C(n-1,1)+.....+C(n-1,n-1)=2^(n-1)
n很大,我们可以用欧拉降幂公式。也有是费马小定理(a^b%p=a^(b%(p-1))%p,p是质数)
#include<bits/stdc++.h>
using namespace std;
#define e exp(1)
#define pi acos(-1)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define mem(a,b) memset(a,b,sizeof(a))
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int maxn=1e5+10;
char s[maxn];
ll qpow(ll a,ll b)
{
ll ans=1;
while(b)
{
if(b&1)ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
int main()
{
int T;scanf("%d",&T);
while(T--)
{
scanf("%s",s);
int len=strlen(s);
ll num=0;
for(int i=0; i<len; i++)
{
num=num*10+s[i]-'0';
num=num%(mod-1);
}
if(num==0)puts("1");
else printf("%lld\n",qpow((ll)2,num-1));
}
return 0;
}