【费马小定理+快速幂取模】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 ...
随机推荐
- 所谓的规范以及JDK api文档的重要性
所谓的规范,就是在jee api 文档里对应的接口. 可以从jdk文档和jee文档的目录结构,接口中获取对整个编程范围的把握
- 免费申请一年版Eset NOD32 Antivirus激活码(无限制)- 已失效
You will receive a 1-year license of the antivirus software Eset NOD32 (version 6), including all up ...
- apache的<directory> 语句以及属性的含义
在整完apache和tomcat的之后我觉得有必要把<directory>和它下面的属性捋顺一下 如何访问根目录下的目录http://192.168.1.12/test/ 第一.缺省apa ...
- C# 跨线程更新UI界面的适当的处理方式,友好的退出界面的机制探索
本文主要讲讲C#窗体的程序中一个经常遇到的情况,就是在退出窗体的时候的,发生了退出的异常. 工业软件技术交流群:群1:592132877(满) 群2:948305931 欢迎技术探讨 我们先 ...
- 【ssm】拦截器的原理及实现
一.背景: 走过了双11,我们又迎来了黑色星期五,刚过了黑五,双12又将到来.不管剁手的没有剁手的,估计这次都要剁手了!虽然作为程序猿的我,没有钱但是我们长眼睛了,我们关注到的是我们天猫.淘宝.支付宝 ...
- 前端开发 —— google chart 的使用
1. 引入所需的 js 库 在 <head></head>中 <script src="https://ajax.googleapis.com/ajax/lib ...
- 【计算机视觉】如何使用于仕琪老师的libfacedetect人脸检测库
前言 最近又开始进行人脸检测方向的内容,看到于仕琪老师的多角度检测想试一下,还不清楚原理,先测试效果如何. libfacedetect人脸检测库是深圳大学于仕琪老师发布的开源库,与opencv自带的人 ...
- 【其他】msb-lsb-intel-motorola大小端问题
MSB(Most Significant Bit) 最高有效位: LSB(Least Significant Bit) 最低有效位 intel格式:低字节在前 Motorola格式:高字节在前 参考1 ...
- xgboost 简单测试
#coding=utf8 import pandas as pd from sklearn.model_selection import train_test_split from sklearn.f ...
- requests中获取请求到文本编码格式
1.使用requests模块: import requests 2.通过网络请求,并获取到数据 url = "http://www.stat-nba.com/award/item14.htm ...