HDU 5793 A Boring Question(数论)
2016-08-26 13:11
555 查看
Description
求
其中
Input
第一行一整数T表示用例组数,每组用例输入两个整数n和m
(1<=T<=10000,0<=n<=10^9,2<=m<=10^9)
Output
对于每组用例,输出一个答案,结果模1e9+7
Sample Input
2
1 2
2 3
Sample Output
3
13
Solution
Code
求
其中
Input
第一行一整数T表示用例组数,每组用例输入两个整数n和m
(1<=T<=10000,0<=n<=10^9,2<=m<=10^9)
Output
对于每组用例,输出一个答案,结果模1e9+7
Sample Input
2
1 2
2 3
Sample Output
3
13
Solution
Code
#include<cstdio> #include<iostream> using namespace std; typedef long long ll; #define mod 1000000007ll ll mod_pow(ll a,ll b) { a%=mod; ll ans=1; while(b) { if(b&1)ans=ans*a%mod; a=a*a%mod; b>>=1; } return ans; } int main() { int T; ll n,m; scanf("%d",&T); while(T--) { scanf("%I64d%I64d",&n,&m); ll ans=mod_pow(m,n+1)-1; ans=(ans%mod+mod)%mod; ans=ans*mod_pow(m-1,mod-2)%mod; printf("%I64d\n",ans); } return 0; }
相关文章推荐
- HDU 5793 A Boring Question(推公式+求逆元)——2016 Multi-University Training Contest 6 (1001)
- HDU 5793 A Boring Question (逆元+快速幂+费马小定理) ---2016杭电多校联合第六场
- 16 多校 6 - A - A Boring Question (HDU - 5793)
- 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 A Boring Question (数学 + 快速幂 + 乘法逆元)
- HDU 5793 A Boring Question (找规律+快速幂)
- hdu 5793 A Boring Question(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 打表找规律
- HDU-5793 A Boring Question(打表找规律)
- hdu-5793 A Boring Question(二项式定理)