ACM-ICPC 2018 Jiaozuo Cyber ​​Pre-match G-question

Give Candies

  •  1000ms
  •  65536K

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).

样样输入Copy

1
4

样出出Copy

8

题来源

思维:

This question is very simple, first of all we It is easy to see that the answer is 2^(n - 1), but since n is very large, the direct fast power is definitely not working, so you can carry it in and ask for

obviously 2^(10n) = (2^n ) ^10, since the power is n - 1, so you can't blindly divide by 2 at the end. You can use the Fermat's theorem to find the inverse element offline, so you can solve the

code:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = (ll)1e9 + 7;
const ll maxn = (ll)1e5 + 10;
const ll inv = 500000004;
char num[maxn];
ll quick(ll a,ll b)
{
    ll res = 1;
    while (b)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
int main()
{
    int t;
    scanf("%d",&t);
    while (t --)
    {
        scanf("%s",num);
        int len = strlen(num);
        ll ans = 1;
        for (int i = 0;i < len;i ++)
        {
            ans = quick(ans,10);
            ans = ans * quick(2,num[i] - '0') % mod;
        }
        ans = ans * inv % mod;
        printf("%lld\n",ans);
    }
    return 0;
}