hdu 5793 A Boring Question(2016第六场多校)
A Boring Question
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 487 Accepted Submission(s):
271
∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=?
We define that (kj+1kj)=kj+1!kj!(kj+1−kj)! . And (kj+1kj)=0 while kj+1<kj .
You have to get the answer for each n and m that given to you.
For example,if n=1 ,m=3 ,
When k1=0,k2=0,k3=0,(k2k1)(k3k2)=1 ;
Whenk1=0,k2=1,k3=0,(k2k1)(k3k2)=0 ;
Whenk1=1,k2=0,k3=0,(k2k1)(k3k2)=0 ;
Whenk1=1,k2=1,k3=0,(k2k1)(k3k2)=0 ;
Whenk1=0,k2=0,k3=1,(k2k1)(k3k2)=1 ;
Whenk1=0,k2=1,k3=1,(k2k1)(k3k2)=1 ;
Whenk1=1,k2=0,k3=1,(k2k1)(k3k2)=0 ;
Whenk1=1,k2=1,k3=1,(k2k1)(k3k2)=1 .
So the answer is 4.
T ,(1≤T≤10000)
Then T lines follow,the i-th line contains two integers n ,m ,(0≤n≤109,2≤m≤109)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define ll long long
#define mod 1000000007
using namespace std; ll mat(ll a,ll b)///a^b,结果对mod取膜,b的值很大的时候
{
ll c=;
if(b==) return a%mod; ///当b为1时,只剩下最后一个a
else if(b&) ///b为奇数
return mat(a,b-)*a%mod; ///把单独的a拿出来
else ///b为偶数
return mat(a*a%mod,b/)%mod; ///直接相乘,系数除以2
} ll extend_gcd(ll a,ll b,ll &x,ll &y)
{
if(a==&&b==) return -;//无最大公约数
if(b==){x=;y=;return a;}
ll d=extend_gcd(b,a%b,y,x);
y-=a/b*x;
return d;
}
//*********求逆元素*******************
//ax = 1(mod n)
ll mod_reverse(ll a,ll n)
{
ll x,y;
ll d=extend_gcd(a,n,x,y);
if(d==) return (x%n+n)%n;
else return -;
} ll c(ll n,ll m)
{
ll i,j,t1,t2,ans;
t1=((mat(m,n+)-)%mod+mod)%mod;
t2=(m-)%mod;
return t1*mod_reverse(t2,mod)%mod;
} int main()
{
int T,n,m;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
ll ans=c(n,m);
printf("%I64d\n",ans);
}
return ;
}
hdu 5793 A Boring Question(2016第六场多校)的更多相关文章
- HDU 5793 - A Boring Question
HDU 5793 - A Boring Question题意: 计算 ( ∑(0≤K1,K2...Km≤n )∏(1≤j<m) C[Kj, Kj+1] ) % 1000000007=? (C[ ...
- HDU 5793 A Boring Question (逆元+快速幂+费马小定理) ---2016杭电多校联合第六场
A Boring Question Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- HDU 5793 A Boring Question (找规律 : 快速幂+逆元)
A Boring Question 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5793 Description Input The first l ...
- HDU 5793 A Boring Question (找规律 : 快速幂+乘法逆元)
A Boring Question Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- HDU 5793 A Boring Question 多校训练
There are an equation. ∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=?∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1 ...
- HDU 5793 A Boring Question ——(找规律,快速幂 + 求逆元)
参考博客:http://www.cnblogs.com/Sunshine-tcf/p/5737627.html. 说实话,官方博客的推导公式看不懂...只能按照别人一样打表找规律了...但是打表以后其 ...
- 数学--数论--Hdu 5793 A Boring Question (打表+逆元)
There are an equation. ∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=? We define that (kj+1kj)=kj+1!kj! ...
- 2016多校第六场题解(hdu5793&hdu5794&hdu5795&hdu5800&hdu5802)
这场就做出一道题,怎么会有窝这么辣鸡的人呢? 1001 A Boring Question(hdu 5793) 很复杂的公式,打表找的规律,最后是m^0+m^1+...+m^n,题解直接是(m^(n+ ...
- 多校6 1001 HDU5793 A Boring Question (推公式 等比数列求和)
题解:http://bestcoder.hdu.edu.cn/blog/ 多校6 HDU5793 A Boring Question // #pragma comment(linker, " ...
随机推荐
- java.lang.IllegalStateException: 1 matchers expected, 5 recorded.
这是一个很神奇的错误. 常规的出错是因为在mock方法里,其中某一个或者几个参数使用了EasyMock.anyxx(),而其他的使用了具体的值. java.lang.IllegalStateExcep ...
- day37 08-Hibernate的反向工程
反向工程:先创建表,创建好表之后,就是持久化类和映射文件可以不用你写,而且你的DAO它也可以帮你生成.但是它生成的DAO可能会多很多的方法.你可以不用那么多方法,但是它里面提供了这种的.用hibern ...
- 高可用服务 AHAS 在消息队列 MQ 削峰填谷场景下的应用
在消息队列中,当消费者去消费消息的时候,无论是通过 pull 的方式还是 push 的方式,都可能会出现大批量的消息突刺.如果此时要处理所有消息,很可能会导致系统负载过高,影响稳定性.但其实可能后面几 ...
- Codeforces 449B
题目链接 B. Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- LintCode刷题笔记-- BackpackII
标记: 动态规划 问题描述: Given n items with size Ai, an integer m denotes the size of a backpack. How full you ...
- day38 16-Spring的Bean的装配:注解的方式
Struts 2和hibernate也使用注解,但是使用注解在以后的开发中应用不多.但是可以说在整合的时候如何进行注解开发.在Spring中,注解必须会玩. package cn.itcast.spr ...
- tablespaces
select * from user_tablespaces; select username,default_tablespace from user_users;
- 微信小程序分析见解
前两天朋友圈都快被小程序给刷爆了: 对于小程序这方面, 由于没有公测的资格.所以翻阅了许许多多的资料,来了解一下小程序: 微信小程序: 小程序是一种不需要下载安装即可使用的应用,它实现了应用&quo ...
- R语言实现Xbar-R控制图
R语言实现Xbar-R控制图 Xbar-R控制图在质量管理中主要用于对计量数据进行检测,以达到控制对象质量的目的. 虽然用Excel可以轻松实现控制图的操作,不过作为R软件初学者,我试着用仅有的一点R ...
- iOS 开发该选择Blocks还是Delegates
http://www.cocoachina.com/ios/20150925/13525.html 前文:网络上找了很多关于delegation和block的使用场景,发现没有很满意的解释,后来无意中 ...