1. 程式人生 > >ACM-ICPC 2018 焦作賽區網路預賽 G Give Candies —— 大數

ACM-ICPC 2018 焦作賽區網路預賽 G 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≤10 100000

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

樣例輸入 複製 1 4 樣例輸出 複製 8

題目連結:https://nanti.jisuanke.com/t/31716

題意: 有n個人和n個糖,來一個人就要給至少給一個,給完為止,問有多少種方法 題解: 這個很容易想到做法,相當於n個球放到n個盒子裡+n個球放到n-1個盒子裡… 就是2n1 那麼就是讀入的問題了,剛開始找的模板不怎麼會用,一直wa,後來換了一個就過了,他是先讀入n,之後一位一位用尤拉降冪讀進去。


#include <cstdio>

#include <cstring>

#include <cmath>

typedef long long LL;

#define MAXN 1000100

const LL MOD=1e9+7;

char
c[MAXN]; LL pow_mod(LL a, LL n) { LL ans = 1; while(n) { if(n&1) ans = ans*a%MOD; a = a*a%MOD; n >>= 1; } return ans; } int main() { int t;scanf("%d",&t); while(t--) { scanf("%s", c); LL n = 0; int len=strlen(c); for(int i = 0;i<len;i++) n = (n*10+c[i]-'0')%(MOD-1); printf("%I64d\n", ((LL)pow_mod(2,n-1+MOD-1)*pow_mod(2,MOD-1))%MOD); } return 0; }