1. 程式人生 > >焦作2018網路賽_Give Candies(費馬小定理+快速冪)

焦作2018網路賽_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 N.

1≤T≤100

1≤N≤10^100000

Output

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

樣例輸入複製

1
4

樣例輸出複製

8

題目來源

#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<k;i++)
#define per(i,j,k) for(int i=j;i<=k;i++)
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;
typedef long long ll;
const ll mod = 1000000007 ;

ll quick_pow(ll a,ll b)
{
    ll ans=1;
    ll tem=a;
    while(b)
    {
        if(b&1) ans=ans*tem%mod;
        tem=tem*tem%mod;
        b>>=1;
    }
    return ans;
}
int main(void)
{
    IO
    int T;cin>>T;
    while(T--)
    {
        string s;
        cin>>s;
        ll p=0;
        rep(i,0,s.length())
        {
            p=(p*10+s[i]-'0')%(mod - 1);
        }
        cout<<quick_pow(2,p-1)<<endl;   //答案要求的是2^(n-1)
    }
}