There are NNN 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)(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 TTT, the number of test case.

The next TTT lines, each contains an integer NNN.

1≤T≤1001 \le T \le 1001≤T≤100

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

Output

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

样例输入 复制

1
4

样例输出 复制

8

题意:
给n个小孩发糖果,总共有n个糖果,小孩按顺序排好,把糖果分发,不必每个小孩都有糖果,但是如果不是每个孩子都有糖果,那么只能是在后面的小孩没有糖果。问有多少种方案。 题解:
找到规律,对于每一个n,方案数为2^n,这里应用快速幂,但是n太大了,想办法减小它,这里要应用一下费马小定理(假如p是质数,且gcd(a,p)=1,那么 a(p-1)≡1(mod p)),即(a^n)%mod,如果mod为质数,a^(n%(mod-1))%mod。(本题中mod为1e9+7) 代码:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod=1e9+; ll Pow(ll a,ll b)
{
ll ans=;
a%=mod;
while(b){
if(b&) ans=ans*a%mod;
a=a*a%mod;
b=b>>;
}
return ans;
} int main()
{
int t;
ll i,n;
char a[];
cin>>t;
while(t--){
scanf("%s",a);
int len=strlen(a);
n=;
for(i=;i<len;i++){
n=(n*+(a[i]-''))%(mod-);
}
printf("%lld\n",Pow(,n-)%mod);
}
return ;
}

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(隔板定理 + 小费马定理 + 大数取模,组合数求和)题解

    题意:给你n个东西,叫你把n分成任意段,这样的分法有几种(例如3:1 1 1,1 2,2 1,3 :所以3共有4种),n最多有1e5位,答案取模p = 1e9+7 思路:就是往n个东西中间插任意个板子 ...

  5. ACM-ICPC 2018 焦作赛区网络预赛- G:Give Candies(费马小定理,快速幂)

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

  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. ACM-ICPC 2018 焦作赛区网络预赛

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

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

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

  9. ACM-ICPC 2018 焦作赛区网络预赛- L:Poor God Water(BM模板/矩阵快速幂)

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

随机推荐

  1. MYSQL ERROR 1045 (28000) Access denied for user (using password YES)问题的解决

    我的Linux是Centos6.7的版本,本机上Mysql突然怎么连接都进不去 报错:MYSQL ERROR 1045 (28000) Access denied for user (using pa ...

  2. Swiper.js使用教程

    官网地址:(http://www.swiper.com.cn/). 一.Swiper.js简介: Swiper(前称Swiper master) 是一款免费以及轻量级的移动设备触控滑块的js框架,使用 ...

  3. AMD/CMD/CommonJs到底是什么?它们有什么区别?

    知识点1:AMD/CMD/CommonJs是JS模块化开发的标准,目前对应的实现是RequireJs/SeaJs/nodeJs.   知识点2:CommonJs主要针对服务端,AMD/CMD主要针对浏 ...

  4. Python 转路由之uplink

    项目描述 1.为客制化的Web API接口建立可重用的对象 2.可以与Requests,asyncio和Twisted 快速开始 Uplink把你的HTTP API接口转化成一个Python的类 fr ...

  5. Flask表单(form)的应用

    导入模块request模块 #指定请求方式,使用methods属性 @app.route("/",methods=['GET','POST']) def index(): #判断c ...

  6. Tip:什么是JavaBean

    可视化JavaBean  非可视化JavaBean(分:值JavaBean和工具JavaBean) JavaBean是一个遵循特定写法的Java类,它通常具有如下特点: 这个Java类必须具有一个无参 ...

  7. Create AI Guard Class

    创建FPSAIGuard类 不需要玩家输入,删除多余的函数 FPSAIGuard.h #include "CoreMinimal.h" #include "GameFra ...

  8. Thymeleaf在前台下拉列表获取后台传的值

    Thymeleaf在前台下拉列表获取后台传的值 后台添加代码: /** * 新增机构 */ @GetMapping("/add") public String add(ModelM ...

  9. Sql server—— for xml path简单用法(可以按照分组把相同组的列中的不同的值,像字符串一样拼接在一起显示在分组之后的列中。)

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAI8AAACWCAIAAABo2EyXAAAKeklEQVR4nO2dy27rNh7G+U7CFIrfZX

  10. java知识点4

    架构篇 分布式 数据一致性.服务治理.服务降级 分布式事务 2PC.3PC.CAP.BASE. 可靠消息最终一致性.最大努力通知.TCC Dubbo 服务注册.服务发现,服务治理 分布式数据库 怎样打 ...