ACM-ICPC 2018 焦作赛区网络预赛 G Give Candies
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的更多相关文章
- 【费马小定理+快速幂取模】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 ...
- ACM-ICPC 2018 焦作赛区网络预赛 G. Give Candies (打表找规律+快速幂)
题目链接:https://nanti.jisuanke.com/t/31716 题目大意:有n个孩子和n个糖果,现在让n个孩子排成一列,一个一个发糖果,每个孩子随机挑选x个糖果给他,x>=1,直 ...
- ACM-ICPC 2018 焦作赛区网络预赛 G Give Candies(高精度求余)
https://nanti.jisuanke.com/t/31716 题意 n颗糖果n个人,按顺序给每个人任意数目(至少一个)糖果,问分配方案有多少. 分析 插板法或者暴力打表后发现答案就为2^(n- ...
- 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个东西中间插任意个板子 ...
- ACM-ICPC 2018 焦作赛区网络预赛- G:Give Candies(费马小定理,快速幂)
There are N children in kindergarten. Miss Li bought them NNN candies. To make the process more inte ...
- ACM-ICPC 2018 焦作赛区网络预赛 G题 Give Candies
There are NN children in kindergarten. Miss Li bought them NN candies. To make the process more inte ...
- ACM-ICPC 2018 焦作赛区网络预赛
这场打得还是比较爽的,但是队友差一点就再过一题,还是难受啊. 每天都有新的难过 A. Magic Mirror Jessie has a magic mirror. Every morning she ...
- ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)
ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...
- 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 ...
随机推荐
- python3.x与2.x区别
1.性能 Py3.0运行 pystone benchmark的速度比Py2.5慢30%.Guido认为Py3.0有极大的优化空间,在字符串和整形操作上可 以取得很好的优化结果. Py3.1性能比Py2 ...
- grep 打印相关行内容
grep 打印相关行数常用参数: -r:关键字 -c:打印符合要求的行数 -i:忽略大小写 -n:输出行和行号 -v:打印不符合要求的行,即反选 -A:后跟数字(有无空格都可以),例如 -A3表示打印 ...
- 很实用的php的缓存类文件示例
http://www.php.cn/php-weizijiaocheng-376603.html <?php /* * 缓存类 cache */ class cache { //缓存目录 var ...
- 小程序前端防止重复点击请求api的简陋方法
upload: function () { let that = this; let {uploadFlag} = that.data; if (that.data.uploadFlag) { ret ...
- 第28月第3天 c语言读写文件
1. int ConfigIniFile::OpenFile( const char* szFileName ) { FILE *fp; size_t nLen; int nRet; CloseFil ...
- 第27月第12天 webrtc ios openssl boost
1. source 'https://github.com/CocoaPods/Specs.git' target 'YOUR_APPLICATION_TARGET_NAME_HERE' do pla ...
- java调试与排错
参考网址:http://www.doc88.com/p-461115156632.html 一.Java程序调试与错误收集 1.Web程序的调试与排错:尽量使用System.out.println() ...
- Leetcode#657. Judge Route Circle(判断路线成圈)
题目描述 初始位置 (0, 0) 处有一个机器人.给出它的一系列动作,判断这个机器人的移动路线是否形成一个圆圈,换言之就是判断它是否会移回到原来的位置. 移动顺序由一个字符串表示.每一个动作都是由一个 ...
- 🍓 react16.2新特性 🍓
react16.2新特性:组件中可以一次性return 多个子元素(子组件)了,也就是说,想return多个子元素,不用在外面包一个父盒子了. 方法一:把要return的元素放在一个空的jsx里面 方 ...
- python问题:AttributeError: 'module' object has no attribute 'SSL_ST_INIT'
AttributeError: 'module' object has no attribute 'SSL_ST_INIT' 问题背景: 下载工具wydomain,安装依赖包以后,出现下图问题. 几经 ...