A Boring Question
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5793
Description
![](http://images2015.cnblogs.com/blog/764119/201608/764119-20160804173305559-605626236.png)
The first line of the input contains the only integer T,
Then T lines follow,the i-th line contains two integers n,m.
Output
For each n and m,output the answer in a single line.
2
1 2
2 3
Sample Output
3
13
Source
2016 Multi-University Training Contest 6
##题意:
用m个不大于n的数构成一个序列,对每个序列求C(ki+1,ki)的连乘积.
对所有可能的序列,累加上述连乘积.
##题解:
还是打表找的规律...(好弱啊)
f(1,2)=3; f(2,2)=7;
f(1,3)=4; f(2,3)=13;
f(1,4)=5; f(2,4)=21;
f(1,5)=6; f(2,5)=31;
......
打了个5*5的表后发现规律:(后附打表代码)
f(n,m) = f(n-1,m) + m^n;
= m^0 + m^1 + m^2 + ... + m^n; (等比数列求和)
= (1 - m^(n+1)) / (1 - m);
然后用快速幂和乘法逆元求出上式即可.
官方题解:
##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include