hdu 5793 A Boring Question 推公式(多校)

题目:http://acm.hdu.edu.cn/showproblem.php?pid=5793
分析:
队内大牛手画了几组样例,然后就推出公式了QAQ
正解看大神博客:http://www.cnblogs.com/qscqesze/p/5737450.html#3483144

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;

ll qmod(ll a,ll n)
{
    ll ans=1;
    for(;n;n>>=1){
        if(n&1)ans=ans*a%mod;
        a=a*a%mod;
    }
    return ans;
}
int main()
{
    int T;scanf("%d",&T);
    while(T--){
        ll n,m;
        scanf("%lld%lld",&n,&m);
        printf("%lld
",(qmod(m,n+1)-1)*qmod(m-1,mod-2)%mod);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/01world/p/5762815.html