【费马小定理+快速幂取模】ACM-ICPC 2018 焦作赛区网络预赛 G. Give Candies
G. Give Candies
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.
Input
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
Output
For each test case output the number of possible results (mod 1000000007).
样例输入
1
4
样例输出
8
有n个孩子,n个糖果,从第一个孩子开始给,任意给随便数量的糖果,至少给一个
问你一共有多少种不同的给的方案,答案应该为2^(n-1)%1e9+7
n可以到10的100000次方,所以应当用降幂公式
费马小定理 (a^n)%mod,如果mod为质数,a^(n%(mod-1))%mod
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
ll quickpow(ll a,ll b)
{
ll r=1;
while(b)
{
if(b&1) r=r*a%mod;
a=a*a%mod;
b/=2;
}
return r;
}
char s[100005]; int main()
{
int T;
scanf("%d",&T); while(T--)
{
scanf("%s",s);
int len=strlen(s);
ll temp=0;
for(int i=0;i<len;i++)
{
temp=(temp*10+s[i]-'')%(mod-1);
}
temp--;
if(temp<0) temp=mod-1;
printf("%lld\n",quickpow(1LL*2,temp));
}
return 0;
}
转载来自大佬 cherry:
https://blog.csdn.net/qq_41037114/article/details/82716896
【费马小定理+快速幂取模】ACM-ICPC 2018 焦作赛区网络预赛 G. Give Candies的更多相关文章
- 【2018 ICPC焦作网络赛 G】Give Candies(费马小定理+快速幂取模)
There are N children in kindergarten. Miss Li bought them N candies. To make the process more intere ...
- hdu 4704(费马小定理+快速幂取模)
Sum Time Limit: 2000/ ...
- 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 (打表找规律+快速幂)
题目链接:https://nanti.jisuanke.com/t/31716 题目大意:有n个孩子和n个糖果,现在让n个孩子排成一列,一个一个发糖果,每个孩子随机挑选x个糖果给他,x>=1,直 ...
- ACM-ICPC 2018 焦作赛区网络预赛- G:Give Candies(费马小定理,快速幂)
There are N children in kindergarten. Miss Li bought them NNN candies. To make the process more inte ...
- 牛客Wannafly挑战赛13-BJxc军训-费马小定理、分式取模、快速幂
参考:https://blog.csdn.net/qq_40513946/article/details/79839320 传送门:https://www.nowcoder.com/acm/conte ...
- 2014多校第一场 I 题 || HDU 4869 Turn the pokers(费马小定理+快速幂模)
题目链接 题意 : m张牌,可以翻n次,每次翻xi张牌,问最后能得到多少种形态. 思路 :0定义为反面,1定义为正面,(一开始都是反), 对于每次翻牌操作,我们定义两个边界lb,rb,代表每次中1最少 ...
- BZOJ_[HNOI2008]_Cards_(置换+Burnside引理+乘法逆元+费马小定理+快速幂)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1004 共n个卡片,染成r,b,g三种颜色,每种颜色的个数有规定.给出一些置换,可以由置换得到的 ...
- hdu4549(费马小定理 + 快速幂)
M斐波那契数列F[n]是一种整数数列,它的定义如下: F[0] = a F[1] = b F[n] = F[n-1] * F[n-2] ( n > 1 ) 现在给出a, b, n,你能求出F[n ...
随机推荐
- ECharts报表的使用
知道你们懒得手打网址,给你们贴上:http://echarts.baidu.com/echarts2/ 1.下载并解压之后,找到echarts-2.2.7\build\dist\echarts-all ...
- lucene4 Filter
摘要: 关于过滤方面的知识,也就是Filter,如果了解Solr的朋友们,肯定都会知道Solr里面fq这个参数,这个参数的作用其实就是lucene里面的过滤,对一些q参数查询的结果集,做过滤或者限制返 ...
- Win10玩游戏时听歌音量忽大忽小
问题原因是你的声卡被识别成了5.1声道,解决方法: 1.右键桌面右下角小喇叭选择“声音” 2.右键当前的播放设备选择“配置扬声器” 3.选择“立体声”,可以测试一下,然后点击下一步退出,可能会中断当前 ...
- 史前埃及(predynastic egypt)
一个并不复杂的建造发展游戏,却十分有趣 安排工作-收集资源-招募工人-增加生产资源效率or建设科技-招募工人的模式 地表在建设后有明显的变化 同时也可以通过简单的动画展示工人的工作分配
- cocos2d-x中用到的一些宏
最近我们的cocos2d-x游戏项目已经进入了正式开发的阶段了,几个dev都辛苦码代码.cocos2d-x还是一套比较方便的api的,什么action啊.director啊.ccpoint啊都蛮便捷的 ...
- Ubuntu 16.04 安装 PyCharm
https://blog.csdn.net/zhuanshu666/article/details/73554885
- 工业通信的开源项目 HslCommunication 介绍
前言: 本项目的孵化说来也是机缘巧合的事,本人于13年杭州某大学毕业后去了一家大型的国企工作,慢慢的走上了工业软件,上位机软件开发的道路.于14年正式开发基于windows的软件,当时可选的技术栈就是 ...
- 【转】C# Socket通信编程
https://www.cnblogs.com/dotnet261010/p/6211900.html#undefined 一:什么是SOCKET socket的英文原义是“孔”或“插座”.作为进程通 ...
- Tomcat结合nginx使用入门
Nginx: Nginx是一款高性能,轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器. 特点是:占有内存少,并发能力强. 反向代理服务器: 反向代理(Reverse ...
- unbtu使用笔记
安装fcitx输入法: sudo apt-get install fcitx-table-wbpy 再配置http://www.cnblogs.com/imsoft/p/4368550.html vi ...