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. ie edge 自动给数字加下划线

    <meta name="format-detection" content="telephone=no,email=no,address=no">

  2. Oracle多个字段如何合并成一个字段显示

    今天记录一下在oracle中多个字段如何和合并成一个字段,使用到符号“||” 1.组合查询的数据 1)组合前查询的语句 -- 组合前数据的字段 -- select A.MID CATE_ID,A.Co ...

  3. vs2015 出现Lc.exe 已退出,代码为-1的问题,如何解决

    今天在代码运行时,出现lc.exe已退出,代码为-1 的问题

  4. 【Jmeter_WebService接口】对项目中的GetProduct接口生成性能脚本

    一.环境信息 https://xxx.xxx.svc?wsdl 用户名:username 密码:password 对其中的GetProduct接口进行测试 二.通过soapui获取soup请求信息 1 ...

  5. js编码函数一些区别

    s对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decodeURIComponent 1、 ...

  6. UVa LA 3695 - Distant Galaxy 前缀和,状态拆分,动态规划 难度: 2

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  7. flask下载zip文件报错TypeError

    报错内容:TypeError: make_conditional() got an unexpected keyword argument 'accept_ranges' 报错行自己代码如下: dir ...

  8. java项目性能测试过程记录

    一 准备环境和指标 1.主机三台(linux,这里显示的都是伪主机地址):最好用干净的机子,做性能测试的时候别装其他东西在上面跑.  100.22.0.98  部署自己的项目服务 100.22.0.9 ...

  9. 7.4 C++标准模板库(STL)的概念

    参考:http://www.weixueyuan.net/view/6401.html 总结:  标准模板库为C++提供了完善的数据结构及算法. 标准模板库包括三部分:容器.算法和迭代器. 容器是对象 ...

  10. vivado对task和function的可综合支持

    手册UG901,对vivado可综合的语句支持进行了描述,HDL包括:verilog-2001,system-verilog,VHDL: verilog-2001扩展了对task和function的支 ...