标签:wan inpu follow its sub return search log style
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 865 Accepted Submission(s): 534
题解:
找规律...
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 (找规律 : 快速幂+乘法逆元)
标签:wan inpu follow its sub return search log style
原文地址:http://www.cnblogs.com/stepping/p/7154752.html