2018焦作网络赛G-Give Candies

 G: Give Candies

时间限制: 1 Sec  内存限制: 128 MB
题目描述
There are N children in kindergarten. Miss Li bought them N 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), 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. 
输入
The first line contains an integer T, the number of test case.
The next T lines, each contains an integer N.
1 ≤ T ≤ 100
1 ≤ N ≤ 10^100000
输出
For each test case output the number of possible results (mod 1000000007).

样例输入

1
4

样例输出
8

分析

ans=2^(n-1)

 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 const int maxn=1e7+7;
 5 const ll mod=1e9+7;
 6 char arr[maxn];
 7 ll bit[15];
 8 ll qpow(ll a,ll b,ll c)
 9 {
10     if(b==0)return 1;
11     ll ans=1;
12     while(b)
13     {
14         if(b&1)ans=(ans*a)%mod;
15         a=a*a%mod;
16         b>>=1;
17     }
18     return ans%mod;
19 }
20 ll inv(ll a,ll m)
21 {
22     if(a==1)return 1;
23     return inv(m%a,m)*(m-m/a)%m;
24 }
25 int main()
26 {
27     int t;
28     scanf("%d",&t);
29     bit[0]=1;
30     ll inv2=inv(2,mod);
31     for(int i=1;i<10;i++)
32     {
33         bit[i]=bit[i-1]*2;
34     }
35     while(t--)
36     {
37         scanf("%s",arr);
38         int len=strlen(arr);
39         ll ans=1;
40         for(int i=0;i<len;i++)
41         {
42             ans=qpow(ans,10,mod)%mod;
43             ans=ans*bit[arr[i]-'0']%mod;
44         }
45         ans*=inv2;
46         printf("%lld\n",(ans+mod)%mod);
47     }
48     return 0;
49 }
View Code
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值