HDU 5793 A Boring Question (找规律 : 快速幂+乘法逆元)
2017-07-12 12:07
405 查看
A Boring Question
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 865 Accepted Submission(s): 534
[align=left]Problem Description[/align]
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 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.
[align=left]Input[/align]
The first line of the input contains the only integer T,(1≤T≤10000)
Then T lines follow,the i-th line contains two integers n,m,(0≤n≤109,2≤m≤109)
[align=left]Output[/align]
For each n and m,output the answer in a single line.
[align=left]Sample Input[/align]
2
1 2
2 3
[align=left]Sample Output[/align]
3
13
[align=left]Author[/align]
UESTC
[align=left]Source[/align]
2016 Multi-University Training Contest 6
[align=left]Recommend[/align]
wange2014
题解:
找规律...
f(0,2)=1; f(1,2)=3; f(2,2)=7; f(3,2)=15
f(0,3)=1; f(1,3)=4; f(2,3)=13;
f(0,4)=1; f(1,4)=5; f(2,4)=21;
f(0,5)=1; f(1,5)=6; f(2,5)=31;
f(n,m)=f(n-1,m)*m+1
所以 f(n,m)=(m^(n+1)-1)/(m-1)
//#include <iostream> #include<bits/stdc++.h> using namespace std; const long long mod=1000000007; long long ans,n,m; int T; long long poww(long long a,long long b) { long long ans=1; while(b) { if (b%2==1) ans=(ans*a)%mod; a=(a*a)%mod; b/=2; } return ans; } int main() { scanf("%d",&T); for(;T>0;T--) { scanf("%lld%lld",&n,&m); long long ans=poww(m,n+1); ans=(ans+mod-1)%mod; ans=(ans*poww(m-1,mod-2))%mod; printf("%lld\n",ans); } return 0; }
相关文章推荐
- HDU 5793 A Boring Question (快速幂 + 乘法逆元 + 费马小定理)
- HDU 5793 A Boring Question (找规律 : 快速幂+逆元)
- Hdu 5793 A Boring Question【暴力打表+找规律+求逆元+快速幂+快速积】
- hdu 5793 A Boring Question (数学 + 快速幂 + 乘法逆元)
- HDU 5793 A Boring Question (找规律+快速幂)
- HDU 5793 A Boring Question(快速幂+求逆元)
- (HDU 5793)2016 Multi-University Training Contest 6 A Boring Question (规律)
- HDU-5793 A Boring Question(打表找规律)
- HDU-5793-A Boring Question-打表找规律加模逆元
- HDU 5793 A Boring Question【快速幂+逆元】
- HDU 5793 A Boring Question 打表找规律
- hdu 5793 A Boring Question(2016 Multi-University Training Contest 6——快速幂取模)
- 打表找规律+快速幂+求逆元______A Boring Question(hdu 5793 2016多校第六场)
- hdu_5793_A Boring Question(打表找规律)
- HDU-5793-A Boring Question(打表找规律)
- hdu-5793 A Boring Question 打表找规律
- HDU - 5793 A Boring Question 数学(打表找规律)
- HDU 5793 A Boring Question(快速幂&求逆元)
- HDU 5793 A Boring Question(多校6)
- hdu 5793 A Boring Question(2016第六场多校)