There are N 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), 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 NNN.

1≤T≤100

1≤N≤10^100000

Output

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

样例输入

1
4

样例输出

8

题目来源

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

题意

计算2^(n-1)的值

思路

利用费马小定理:求出(n-1)%(1e9+7)的值,然后利用快速幂计算结果

注意:用int型会TLE,要用long long

#include <bits/stdc++.h>
#define ms(a) memset(a,0,sizeof(a))
#define ll long long
const ll maxn=1e6+10;
const int mod=1e9+7;
using namespace std;
char ch[maxn];
ll Pow(ll a, ll b)
{
ll res=1;
while(b)
{
if(b&1)
res=res*a%mod;
b>>=1;
a=a*a%mod;
}
return res;
}
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
register int t;
ll ans,l;
cin>>t;
while(t--)
{
ans=0;
cin>>ch;
l=strlen(ch);
for(register int i=0;i<l;i++)
{
ans=ans*10+ch[i]-'0';
ans%=(mod-1);
}
cout<<Pow(2,ans-1)<<endl;
}
return 0;
}

ACM-ICPC 2018 焦作赛区网络预赛- G:Give Candies(费马小定理,快速幂)的更多相关文章

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

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

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

  3. ACM-ICPC 2018 焦作赛区网络预赛 G Give Candies(高精度求余)

    https://nanti.jisuanke.com/t/31716 题意 n颗糖果n个人,按顺序给每个人任意数目(至少一个)糖果,问分配方案有多少. 分析 插板法或者暴力打表后发现答案就为2^(n- ...

  4. ACM-ICPC 2018 焦作赛区网络预赛 G Give Candies

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

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

  6. ACM-ICPC 2018 焦作赛区网络预赛 G题 Give Candies

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

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

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

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

    这场打得还是比较爽的,但是队友差一点就再过一题,还是难受啊. 每天都有新的难过 A. Magic Mirror Jessie has a magic mirror. Every morning she ...

  9. ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)

    ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...

随机推荐

  1. 微信支付 php兼容问题

    总结: php7 已删除 HTTP_RAW_POST_DATA  获取时需要file_get_contents("php://input"); 下面的是兼容方法. //存储微信的回 ...

  2. Win10系列:UWP界面布局基础6

    资源合并 前面提到过,可以将资源字典定义在单独的XAML文件中,这样的文件被称为资源字典文件.那么,在需要引用文件中的资源时可以通过ResourceDictionary元素的MergedDiction ...

  3. 【资料搜集】Python学习

    python学习手册 | 演道网 http://dev.go2live.cn/python/python%e5%ad%a6%e4%b9%a0%e6%89%8b%e5%86%8c.html

  4. 执行这些代码, Edit1只能输入数字,小数点和负号,负号和小数点只能输入一个,负号必须在最前,粘贴的数字必须完全正确.

    执行这些代码, Edit1只能输入数字,小数点和负号,负号和小数点只能输入一个,负号必须在最前,粘贴的数字必须完全正确. type TForm1 = class(TForm) Edit1: TEdit ...

  5. 向量空间模型(VSM)在文档相似度计算上的简单介绍

    C#实现在: http://blog.csdn.net/Felomeng/archive/2009/03/25/4023990.aspx 向量空间模型(VSM:Vector space model)是 ...

  6. Cracking The Coding Interview 3.5

    //Implement a MyQueue class which implements a queue using two stacks. #include <iostream> #in ...

  7. windows剪贴板

    0x01  Windows剪贴板 Windows剪贴板是一种比较简单同时也是开销比较小的IPC(InterProcess Communication,进程间通讯)机制.Windows系统支持剪贴板IP ...

  8. CreateThread和_beginthread区别及使用

    CreateThread 是一个Win 32API 函数, _beginthread 是一个CRT(C Run-Time)函数, 他们都是实现多线城的创建的函数,而且他们拥有相同的使用方法,相同的参数 ...

  9. 第三节 java 数组

    一维数组: 同一种类型数据的集合,其实数组就是一个容器. 好处: 可以自动给数组中的元素从0开始编号,方便操作这些元素. 格式1: 元素类型[]  数组名 = new 元素类型 [元素个数或者元素长度 ...

  10. BeanUtils.copyProperties方法,当属性Date为null解决

    问题描述:org.apache.commons.beanutils user对象和formBean对象都有属性birthday,而且都是java.sql.Date类型的 当进行BeanUtils.co ...