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的更多相关文章

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

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

  2. hdu 4704(费马小定理+快速幂取模)

    Sum                                                                                Time Limit: 2000/ ...

  3. 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个东西中间插任意个板子 ...

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

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

  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. 牛客Wannafly挑战赛13-BJxc军训-费马小定理、分式取模、快速幂

    参考:https://blog.csdn.net/qq_40513946/article/details/79839320 传送门:https://www.nowcoder.com/acm/conte ...

  7. 2014多校第一场 I 题 || HDU 4869 Turn the pokers(费马小定理+快速幂模)

    题目链接 题意 : m张牌,可以翻n次,每次翻xi张牌,问最后能得到多少种形态. 思路 :0定义为反面,1定义为正面,(一开始都是反), 对于每次翻牌操作,我们定义两个边界lb,rb,代表每次中1最少 ...

  8. BZOJ_[HNOI2008]_Cards_(置换+Burnside引理+乘法逆元+费马小定理+快速幂)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1004 共n个卡片,染成r,b,g三种颜色,每种颜色的个数有规定.给出一些置换,可以由置换得到的 ...

  9. 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 ...

随机推荐

  1. OPENWRT常用设置

    常用设置: 计划任务,定时重启 系统--计划任务,每行一个计划任务. 然后是计划任务列表的格式: [minute] [hour] [day of month] [month] [day of week ...

  2. 投资银行的IT部门——不同之处与常见误解

    投资银行的IT部门——不同之处与常见误解 说了这么多投资银行,投行里面的IT部门究竟是做什么的呢?在过去,投资银行仅靠纸.笔.计算器就能做生意了.但是在今天,所有的部门都要依靠IT技术.交易部门甚至是 ...

  3. L1-050 倒数第N个字符串

    给定一个完全由小写英文字母组成的字符串等差递增序列,该序列中的每个字符串的长度固定为 L,从 L 个 a 开始,以 1 为步长递增.例如当 L 为 3 时,序列为 { aaa, aab, aac, . ...

  4. iOS多线程编程:线程同步总结

    1:原子操作 - OSAtomic系列函数 iOS平台下的原子操作函数都以OSAtomic开头,使用时需要包含头文件<libkern/OSBase.h>.不同线程如果通过原子操作函数对同一 ...

  5. jquery offset(),

    offset() 一.语法 1. 返回偏移坐标 $(selector).offset(); top: $(selector).offset().top; left: $(selector).offse ...

  6. PyQt5编程:鼠标事件

    参考链接:https://www.cnblogs.com/zhuluqing/p/9028816.html 一.每个事件都被封装成相应的类: pyqt中,每个事件类型都被封装成相应的事件类,如鼠标事件 ...

  7. a demo for how to use QThread

    /******************************************************************* * a demo for how to use QThread ...

  8. springboot项目文件上传(绝对路径)并使用tomcat虚拟路径进行图片预览

    前言 项目中,需要上传文件,但是可能会比较多,所以不能放入项目目录中,需要指定目录并按顺序放置.并且:还需要这些数据可以预览(图片等). 那么问题就是:上传完成之后我存入服务器,并拿到绝对路径,存入数 ...

  9. mvc之URL篇

    一.根据路由系统生成友好的URL ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName); 会根据当前的路 ...

  10. 习题3.5 求链表的倒数第m个元素(20 分)浙大版《数据结构(第2版)》题目集

    请设计时间和空间上都尽可能高效的算法,在不改变链表的前提下,求链式存储的线性表的倒数第m(>0)个元素. 函数接口定义: ElementType Find( List L, int m ); 其 ...