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 ≤ 10^100000
Output
For each test case output the number of possible results (mod 1000000007).
样例输入
1
4
样例输出
8
给任意多个小朋友分N块糖,给每个小朋友可以分0~N块糖,问有多少种不同的分法?
思路:
N块糖,用隔板法,共N-1个空,每个空可以选择加隔板和不加隔板。
2^(N-1),N比较大,用费马小定理降幂。
费马小定理:
p为质数
费马小定理降幂应用:
根据
可得
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+100;
const ll Mod=1e9+7;
char s[N];
ll mod_power(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;
while(cin>>T)
{
while(T--)
{
cin>>s;
ll n=0;
int len=strlen(s);
for(int i=0;i<len;i++)
{
n=(n*10+(s[i]-'0'))%(Mod-1);//预处理指数
}
cout<<mod_power(2,n-1)<<endl;
}
}
return 0;
}