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 ...
随机推荐
- 常用.net反编译替换正则表达式
.set_([^\(]*) .$ = ------------------ .get_([^\(]*)\(\) .$ ------------------ .get_Item\(([a-z|-]+)\ ...
- Win下安装nvm
nvm 是 windows 下切换 node 版本的管理工具,mac 下可以使用 TJ 写的 n . 1.https://github.com/coreybutler/nvm-windows/rele ...
- HIbernate处理数据更新丢失
使用乐观锁的机制处理: 第一步: 在持久类中添加version属性,并且添加对应的get.set方法; 第二步: 在全局配置文件中配置节点<version name="version& ...
- GCC编译器原理(二)------编译原理一:ELF文件(3)
4.5 String Table:字符串表 字符串表节区包含以 NULL( ASCII 码 0) 结尾的字符序列, 通常称为字符串. ELF 目标文件通常使用字符串来表示符号和节区名称. 对字符串的引 ...
- Kafka如何保证消息不丢失不重复
首先需要思考下边几个问题: 消息丢失是什么造成的,从生产端和消费端两个角度来考虑 消息重复是什么造成的,从生产端和消费端两个角度来考虑 如何保证消息有序 如果保证消息不重不漏,损失的是什么 大概总结下 ...
- 帮助类-从tfs获取数据
using JC.Helper; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.Framework.Cli ...
- 搜索jar包 出现很多 Artifact Id相同 但Group Id不同 的包
举例:将传统本地 javassit-3.17.1-GA.jar包 改成maven引用,pom中 ---Add 输入javassit 搜索 这时候会搜索出超级多 Artifact Id相同 但Group ...
- DeepLearning.ai-Week2-Keras tutorial-the Happy House
1 - Import Packages import numpy as np from keras import layers from keras.layers import Input, Dens ...
- RabbitMQ简单应用の简单队列
(1)首先创建一个maven项目: pom.xml,重点是配置RabbitMQ <dependencies> <dependency> <groupId>junit ...
- Bagging, Boosting, Bootstrap
Bagging 和 Boosting 都属于机器学习中的元算法(meta-algorithms).所谓元算法,简单来讲,就是将几个较弱的机器学习算法综合起来,构成一个更强的机器学习模型.这种「三个臭皮 ...