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;
}

最新文章

  1. jsp中的&lt;%%&gt;和&lt;!%%&gt;的区别
  2. Eclipse Che:下一代基于 Web 的 IDE
  3. Linux登录出现modle is unknow
  4. Windows8不联网直接安装.Net 3.5 Framework的方法
  5. ARM MIPS PowerPC比较
  6. Jquery中的delegate()使用方法介绍
  7. FileSystemXmlApplicationContext方法的绝对路径问题
  8. MySQL中查询表及索引大小的方法
  9. HDU5779 Tower Defence
  10. Day5_递归_二分法
  11. Log4J日志信息配置文件详解
  12. 有关Struts下载文件时报错问题
  13. python打包--pyinstaller打包报错
  14. 并查集:POJ No1703 Find them, Catch them
  15. Fiddler4调试工具配置使用笔记
  16. vue图片、背景图片路径问题
  17. PHP.35-TP框架商城应用实例-后台11-商品分类-删除分类(2种方法)、添加、修改
  18. openstack 创建镜像生成虚拟机不知道密码如何解决
  19. HDU 3586 Information Disturbing (树形DP,二分)
  20. 责任链模式-Chain of Responsibility

热门文章

  1. redis事件监听及在订单系统中的使用
  2. 1-MAVEN 仓库
  3. Pamulinawen--IPA--菲律宾伊洛卡诺语
  4. C++基础知识:泛型编程
  5. poj3279(dfs+二进制枚举思路)
  6. 8.Python爬虫实战一之爬取糗事百科段子
  7. input-event-codes.h
  8. chromium ③
  9. python编码问题分析
  10. Python 关联关系