1. 程式人生 > >Give Candies

Give Candies

There are NN children in kindergarten. Miss Li bought them NN 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)(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 TT, the number of test case.

The next TT lines, each contains an integer NN.

1 \le T \le 1001≤T≤100

1 \le N \le 10^{100000}1≤N≤10100000

Output

For each test case output the number of possible results (mod 1000000007).

樣例輸入複製

#include <iostream>
#include <cstdio>
using namespace std;
#define ll long long
const int maxn=1e5+5;
const int mod=1e9+7;
ll dp;
char s[maxn];
ll quick_mod(ll x,ll y)
{
    ll ret=1;
    for(;y;y>>=1,x=x*x%mod)
        if(y&1) ret=ret*x%mod;
    return ret;
    ll e=1;
    for(ll i=1;i<=y;i++)
    {
        e=e*x%mod;
    }
    return e;
}
int main()
{
    int t,i;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s",s);
        dp=0;
        for(i=0;s[i]!='\0';i++)
        {
            dp=dp*10+(s[i]-48);
            ///dp%=mod-1;
            dp%=mod;
        }
        dp--;
        if(dp==0)printf("1\n");
        else printf("%lld\n",quick_mod(2,dp));
    }
    return 0;
}
1
4

樣例輸出複製

8

題目來源

ACM-ICPC 2018 焦作賽區網路預賽