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 2 n − 1
那么就是读入的问题了,刚开始找的模板不怎么会用,一直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;

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值