您的位置:首页 > 产品设计 > UI/UE

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

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: