2016多校训练Contest6: 1001 A Boring Question hdu5793
来源:互联网 发布:淘宝联盟一淘同时使用 编辑:程序博客网 时间:2024/05/20 17:26
Problem Description
There are an equation.
∑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 eachn and m that given to you.
For example,ifn=1 ,m=3 ,
Whenk1=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.
We define that
You have to get the answer for each
For example,if
When
When
When
When
When
When
When
When
So the answer is 4.
Input
The first line of the input contains the only integer T ,(1≤T≤10000)
ThenT lines follow,the i-th line contains two integers n ,m ,(0≤n≤109,2≤m≤109)
Then
Output
For each n and m ,output the answer in a single line.
Sample Input
21 22 3
Sample Output
313
直接搬运原题的题解了。。
以上。。似乎第三步和第四步是一样的
倒数第二步用二项式定理就可以推出来了
#include<map>#include<cmath>#include<queue>#include<vector>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>using namespace std;long long mod=1000000007;inline long long power(long long x,int y){long long xt=1;while(y!=0){if(y%2==1)xt=xt*x%mod;x=x*x%mod;y/=2;}return xt;}int main(){int T;scanf("%d",&T);while(T>0){T--;int n,m;scanf("%d%d",&n,&m);printf("%I64d\n",(power(m,n+1)+mod-(long long)1)*power(m-1,mod-2)%mod);}return 0;}
0 0
- 2016多校训练Contest6: 1001 A Boring Question hdu5793
- hdu5793 A Boring Question
- HDU5793-A Boring Question
- 2016多校训练Contest6: 1002 A Simple Chess hdu5794
- 2016多校训练Contest6: 1003 A Simple Nim hdu5795
- (多校第六场1001)HDU5793 A Boring Question(逆元,等比数列和取模)
- 【HDU5793】A Boring Question(数学题)
- 2016多校训练Contest6: 1010 Windows 10 hdu5802
- 2016多校训练Contest6: 1008 To My Girlfriend hdu5800
- 2016多校训练Contest6: 1006 Stabilization hdu5798
- HDU5793 A Boring Question (快速幂,逆元)
- 2016多校训练Contest6: 1007 This world need more Zhu hdu5799
- 2016多校训练Contest6: 1011 Zhu’s Math Problem hdu5803
- hdu5793 A Boring Question(推公式or迷之找规律)
- hdu5793——A Boring Question(快速幂+逆元)
- A Boring Question
- A Boring Question HDU
- 2016多校训练总结
- JSTL手稿
- 常见的Linux内核中内存分配
- Java 多线程:Condition 多线程同步关键字
- Android计步器的sensorevent
- 自己写的C++日志类log
- 2016多校训练Contest6: 1001 A Boring Question hdu5793
- JS中的onload事件和jQuery中的ready事件,如何用JS实现jQuery中的ready
- Android 6.0 运行时权限检查机制
- PropertyPlaceholderConfigurer 用法
- SVN 使用详解
- VS C# 获取系统当前时间+timer的作用+无法将类型“int”隐式转换为“string”;
- 求大组合数取模的模板(lucas定理)
- kvm module之create vcpu
- 强制横屏的一种实现 ios