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
#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;
}