题目描述
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.
输入
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
输出
For each test case output the number of possible results (mod 1000000007).
样例输入
1
4
样例输出
8
【代码】
#include<cstdio>
#include<iostream>
#include<algorithm>
#define MAX 100005
#define mod 1000000007
using namespace std;
typedef long long ll;
char s[MAX];
using namespace std;
//公式 a^n%mod=a^(n%(mod-1))%mod
ll qpm(ll x,ll p)//快速幂模版
{
ll ans=1;
while(p)
{
if(p&1)
ans=ans*x%mod;
p>>=1;
x=x*x%mod;
}
return ans;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ll p=0;
int i=0,j;
cin>>s;
for(i=0;i<strlen(s);i++)
{
p*=10;
p+=s[i]-'0';
p=p%(mod-1);
}
p--;
cout<<qpm(2,p);
}
return 0;
}