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. C++简单输入输出-计算火车运行时间

    //写的很差,无力tc 7-4 计算火车运行时间 (17 分) 本题要求根据火车的出发时间和达到时间,编写程序计算整个旅途所用的时间. 输入格式: 输入在一行中给出2个4位正整数,其间以空格分隔,分别 ...

  2. api资源

    转:https://blog.csdn.net/qq_37187976/article/details/79160050

  3. zabbix3.4.7安装在centos 7.4上

    Centos 7.4 安装Zabbix 3.4 一.安装环境 1 [root@juny-18 ~]# cat /etc/redhat-release 2 3 CentOS Linux release ...

  4. python2x 与 python3x 区别

    python2.x 与 python3.x 的区别: 1. python2.x 的源码编码不规范,源码重复较多:python3.x 的源码编码规范,清晰.优美.简单 2. python2.x的默认字符 ...

  5. Fiddler系列教程2:手机抓包图文教程

    上篇Fiddler教程,我们教了大家Fiddler安装配置及如何使用Fiddler进行基本的Http抓包及模拟请求,今天给大家介绍下如何使用Fiddler进行手机抓包. 运行环境为Windows 10 ...

  6. body中的onload()函数和jQuery中的document.ready()有什么区别?

    1.我们可以在页面中使用多个document.ready(),但只能使用一次onload(). 2.document.ready()函数在页面DOM元素加载完以后就会被调用,而onload()函数则要 ...

  7. redis系列--主从复制以及redis复制演进

    一.前言 在之前的文章已经详细介绍了redis入门基础已经持久化相关内容包括redis4.0所提供的混合持久化. 通过持久化功能,Redis保证了即使在服务器宕机情况下数据的丢失非常少.但是如果这台服 ...

  8. java中的方法method

    java中的方法必须存在于类class里,不能独立存在.类是描述具有某种特征的事物,方法则是这类 事物具有的某种功能,通过调用方法可以实现某种特定的功能.方法名一般以小写的动词开头. 例: publi ...

  9. synchronized(八)

    package com.bjsxt.base.sync006;/** * 同一对象属性的修改不会影响锁的情况 * @author alienware * */public class ModifyLo ...

  10. c#继承中的函数调用实例

    using System;   namespace Test {     public class Base     {         public void Print()         {   ...