There are NN children in kindergarten. Miss Li bought them NN 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), 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 TT, the number of test case.

The next TT lines, each contains an integer NN.

1 \le T \le 1001≤T≤100

1 \le N \le 10^{100000}1≤N≤10100000

Output

For each test case output the number of possible results (mod 1000000007).

样例输入复制

1
4

样例输出复制

8

题目来源

ACM-ICPC 2018 焦作赛区网络预赛

题解:费马小定理:a^n%p=a^(n%(p-1))%p;只要求n%(p-1)然后,快速幂求a^()即可:

参考代码为:

 #include<stdio.h>
#define MOD 1000000007
char st[];
int T;
long long sum;
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%s",st);
int i=,j;
sum=;
while(st[i]!='\0')
{
sum=sum*;
sum+=(st[i]-'');
i++;
sum=sum%(MOD-);
}
sum=sum-;
long long temp=,ret=;
while(sum)
{
if(sum&) ret=ret*temp%MOD;
temp=temp*temp%MOD;
sum>>=;
}
printf("%lld\n",ret);
}
return ;
}
  

ACM-ICPC 2018 焦作赛区网络预赛 G题 Give Candies的更多相关文章

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

  2. ACM-ICPC 2018 焦作赛区网络预赛J题 Participate in E-sports

    Jessie and Justin want to participate in e-sports. E-sports contain many games, but they don't know ...

  3. ACM-ICPC 2018 焦作赛区网络预赛 K题 Transport Ship

    There are NN different kinds of transport ships on the port. The i^{th}ith kind of ship can carry th ...

  4. ACM-ICPC 2018 焦作赛区网络预赛 L 题 Poor God Water

    God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...

  5. ACM-ICPC 2018 焦作赛区网络预赛 I题 Save the Room

    Bob is a sorcerer. He lives in a cuboid room which has a length of AA, a width of BB and a height of ...

  6. ACM-ICPC 2018 焦作赛区网络预赛 H题 String and Times(SAM)

    Now you have a string consists of uppercase letters, two integers AA and BB. We call a substring won ...

  7. ACM-ICPC 2018 焦作赛区网络预赛 B题 Mathematical Curse

    A prince of the Science Continent was imprisoned in a castle because of his contempt for mathematics ...

  8. 【费马小定理+快速幂取模】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 ...

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

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

随机推荐

  1. js获取文件里面的所有文件名

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. 通过ESP8266调节继电器时间

    通过ESP8266调节继电器时间 1.继电器选择(可调节时间的继电器) 2.继电器与esp8266的接线[set --- D6,UP --- D5,DOWN --- D1] 3.Arduino 程序 ...

  3. futex-based pthread_cond 源代码分析

    pthread_cond的实现使用了几个futex来协同进行同步,以及如何来实现的. 假定你已经明白 futex,futex-requeue,以及 pthread lowlevellock. < ...

  4. C# 彻底搞懂async/await

    前言 Talk is cheap, Show you the code first! private void button1_Click(object sender, EventArgs e) { ...

  5. robatframework+jenkins+email集成部署方案

    准备工作: 1.jenkins.war包 下载地址:https://jenkins.io/zh/download/ 2.Jdk1.8 下载地址:http://www.oracle.com/techne ...

  6. 新闻实时分析系统-HBase分布式集群部署与设计

    HBase是一个高可靠.高性能.面向列.可伸缩的分布式存储系统,利用Hbase技术可在廉价PC Server上搭建 大规模结构化存储集群. HBase 是Google Bigtable 的开源实现,与 ...

  7. Reactor和Proactor模型

    背景 前面介绍了I/O多路复用模型,那有了I/O复用,有了epoll已经可以使服务器并发几十万连接的同时,还能维持比较高的TPS,难道还不够吗?比如现在在使用epoll的时候一般都是起个任务,不断的去 ...

  8. Java的 FileWriter类 和 FileReader类

    一.FileReader类1,构造方法:FileReader fr = new FileReader(String fileName);//使用带有指定文件的String参数的构造方法.创建该输入流对 ...

  9. LESSON 5 - Markov Sources

    1.      Markov sources The state of the Markov chain is used to represent the “memory” of the source ...

  10. 小白学 Python 爬虫(11):urllib 基础使用(一)

    人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Li ...