There are NNN children in kindergarten. Miss Li bought them NNN 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)(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 TTT, the number of test case.

The next TTT lines, each contains an integer NNN.

1≤T≤1001 \le T \le 1001≤T≤100

1≤N≤101000001 \le N \le 10^{100000}1≤N≤10100000

Output

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

样例输入 复制

1
4

样例输出 复制

8

题意:
给n个小孩发糖果,总共有n个糖果,小孩按顺序排好,把糖果分发,不必每个小孩都有糖果,但是如果不是每个孩子都有糖果,那么只能是在后面的小孩没有糖果。问有多少种方案。 题解:
找到规律,对于每一个n,方案数为2^n,这里应用快速幂,但是n太大了,想办法减小它,这里要应用一下费马小定理(假如p是质数,且gcd(a,p)=1,那么 a(p-1)≡1(mod p)),即(a^n)%mod,如果mod为质数,a^(n%(mod-1))%mod。(本题中mod为1e9+7) 代码:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod=1e9+; ll Pow(ll a,ll b)
{
ll ans=;
a%=mod;
while(b){
if(b&) ans=ans*a%mod;
a=a*a%mod;
b=b>>;
}
return ans;
} int main()
{
int t;
ll i,n;
char a[];
cin>>t;
while(t--){
scanf("%s",a);
int len=strlen(a);
n=;
for(i=;i<len;i++){
n=(n*+(a[i]-''))%(mod-);
}
printf("%lld\n",Pow(,n-)%mod);
}
return ;
}

ACM-ICPC 2018 焦作赛区网络预赛 G Give Candies的更多相关文章

  1. 【费马小定理+快速幂取模】ACM-ICPC 2018 焦作赛区网络预赛 G. Give Candies

    G. Give Candies There are N children in kindergarten. Miss Li bought them N candies. To make the pro ...

  2. ACM-ICPC 2018 焦作赛区网络预赛 G. Give Candies (打表找规律+快速幂)

    题目链接:https://nanti.jisuanke.com/t/31716 题目大意:有n个孩子和n个糖果,现在让n个孩子排成一列,一个一个发糖果,每个孩子随机挑选x个糖果给他,x>=1,直 ...

  3. ACM-ICPC 2018 焦作赛区网络预赛 G Give Candies(高精度求余)

    https://nanti.jisuanke.com/t/31716 题意 n颗糖果n个人,按顺序给每个人任意数目(至少一个)糖果,问分配方案有多少. 分析 插板法或者暴力打表后发现答案就为2^(n- ...

  4. ACM-ICPC 2018 焦作赛区网络预赛G Give Candies(隔板定理 + 小费马定理 + 大数取模,组合数求和)题解

    题意:给你n个东西,叫你把n分成任意段,这样的分法有几种(例如3:1 1 1,1 2,2 1,3 :所以3共有4种),n最多有1e5位,答案取模p = 1e9+7 思路:就是往n个东西中间插任意个板子 ...

  5. ACM-ICPC 2018 焦作赛区网络预赛- G:Give Candies(费马小定理,快速幂)

    There are N children in kindergarten. Miss Li bought them NNN candies. To make the process more inte ...

  6. ACM-ICPC 2018 焦作赛区网络预赛 G题 Give Candies

    There are NN children in kindergarten. Miss Li bought them NN candies. To make the process more inte ...

  7. ACM-ICPC 2018 焦作赛区网络预赛

    这场打得还是比较爽的,但是队友差一点就再过一题,还是难受啊. 每天都有新的难过 A. Magic Mirror Jessie has a magic mirror. Every morning she ...

  8. ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)

    ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...

  9. ACM-ICPC 2018 焦作赛区网络预赛- L:Poor God Water(BM模板/矩阵快速幂)

    God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...

随机推荐

  1. error.c

    #include <stdio.h> #include <errno.h> #include <stdlib.h> #include <string.h> ...

  2. Rsync + inotify 实现文件实时同步

    Rsync 用来实现触发式的文件同步. Inotify-tools是一套组件,Linux内核从2.6.13版本开始提供了inotify通知接口,用来监控文件系统的各种变化情况,如文件存取.删除.移动等 ...

  3. IIS服务器的安全保护措施

    转载自:https://www.williamlong.info/archives/118.html 部分内容做了修改. 通过标注Web服务器安全级别以及可用性的安全策略,网络管理员将能够从容地在不同 ...

  4. Caused by: java.lang.InstantiationException: cn.at.bean.domain.ConstantInt

      org.springframework.jdbc.UncategorizedSQLException: ConnectionCallback; uncategorized SQLException ...

  5. bootstrap-table前端修改后台传来的数据重新进行渲染

    使用bootstrap-table显示数据,后台传回数据以后,可能需要对其做调整,如需要前端为数据添加单位 回到顶部 调整数据代码 $("#"+tableId).bootstrap ...

  6. 20165337岳源 预备作业3:Linux安装及命令入门

    安装虚拟机 按照基于VirtualBox虚拟机安装Ubuntu图文教程的步骤安装虚拟机,遇到的问题通过同学的帮助也得到了解决.例如:虚拟机无法选择64位系统. 常用的Linux命令 Tab 补全命令. ...

  7. JVM内存分配 -Xms128m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=512m

    https://blog.csdn.net/u012882327/article/details/69525166

  8. [转] 理解CheckPoint及其在Tensorflow & Keras & Pytorch中的使用

    作者用游戏的暂停与继续聊明白了checkpoint的作用,在三种主流框架中演示实际使用场景,手动点赞. 转自:https://blog.floydhub.com/checkpointing-tutor ...

  9. SpringBoot编写自定义配置信息

    ⒈编写自定义配置类 1.浏览器配置 package cn.coreqi.security.properties; public class BrowserProperties { private St ...

  10. python set 使用

    创建集合set python set类是在python的sets模块中,大家现在使用的python2.7.x中,不需要导入sets模块可以直接创建集合.>>>set('boy')se ...