HDU5793-A Boring Question
来源:互联网 发布:win域名退出中国 编辑:程序博客网 时间:2024/05/20 17:42
A Boring Question
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 965 Accepted Submission(s): 595
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
Author
UESTC
Source
2016 Multi-University Training Contest 6
Recommend
wange2014
题意:用m个不大于n的数构成一个序列,对每个序列求C(kj+1,kj)的乘积。求出所有可能的序列,累加这些乘积
解题思路:打表找规律
f(1,2)=3; f(1,6)=7; f(2,2)=7; f(2,6)=43; f(3,2)=15
f(1,3)=4; f(1,7)=8; f(2,3)=13; f(2,7)=57; f(3,3)=40
f(1,4)=5; f(1,8)=9; f(2,4)=21; f(2,8)=73; f(3,4)=85
f(1,5)=6; f(1,10)=11; f(2,5)=31; f(2,9)=91; f(3,5)=156
f(1,3)=4; f(1,7)=8; f(2,3)=13; f(2,7)=57; f(3,3)=40
f(1,4)=5; f(1,8)=9; f(2,4)=21; f(2,8)=73; f(3,4)=85
f(1,5)=6; f(1,10)=11; f(2,5)=31; f(2,9)=91; f(3,5)=156
然后找规律:
f(n,m) = f(n-1,m) + m^n = m^0 + m^1 + m^2 + ... + m^n = (1 - m^(n+1)) / (1 - m)
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <cmath>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>#include <functional>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;const LL mod = 1000000007;LL n, m;LL extend_gcd(LL a, LL b, LL &x, LL &y){if (!b){x = 1, y = 0;return a;}LL gcd = extend_gcd(b, a%b, x, y);LL tmp = x;x = y;y = tmp - (a / b)*y;return gcd;}LL qpow(LL a, LL b){LL ans = 1;while (b){if (b & 1) ans = (ans*a) % mod;b >>= 1;a = (a*a) % mod;}return ans;}int main(){int t;scanf("%d", &t);while (t--){scanf("%lld%lld", &n, &m);LL ans = qpow(m, n + 1)-1,x,y;LL tmp = extend_gcd(m - 1, mod, x, y);x = (x % (mod / tmp) + (mod / tmp)) % (mod / tmp);printf("%lld\n", x*ans%mod);}return 0;}
阅读全文
0 0
- hdu5793 A Boring Question
- HDU5793-A Boring Question
- 【HDU5793】A Boring Question(数学题)
- HDU5793 A Boring Question (快速幂,逆元)
- 2016多校训练Contest6: 1001 A Boring Question hdu5793
- hdu5793 A Boring Question(推公式or迷之找规律)
- hdu5793——A Boring Question(快速幂+逆元)
- (多校第六场1001)HDU5793 A Boring Question(逆元,等比数列和取模)
- A Boring Question
- A Boring Question HDU
- 【HDU】5793 A Boring Question
- hdoj5793 A Boring Question【找规律】
- HDU 5793 A Boring Question (数学)
- HDU 5793 A Boring Question 打表找规律
- hdu 5793 A Boring Question 数学
- HDU 5793 A Boring Question(多校6)
- 【HDOJ5793】A Boring Question(数学题)
- 多校6 A Boring Question 5793
- Android调用基于cxf的WebService接口
- POJ
- 实训第一天
- Mac OS: 将PlayFramework应用部署到 Heroku上
- 线程
- HDU5793-A Boring Question
- Java8 Lambda表达式例子
- 轻量级C#网络通信组件StriveEngine —— C/S通信开源demo(附源码)
- 挑战程序竞赛系列(51):4.2 推理与动态规划算法(4)
- 升级 phpStudy 中 MySQL 版本至 5.7.17
- svn分支、主干合并
- HDU 1760 A New Tetris Game
- 深入理解 ruby 中的 eval 与 binding
- 获取多个随机生成的不重复的6位数,不重复的6位数或8位数串