A Boring Question
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 635 Accepted Submission(s): 375
∑
We define that (k
You have to get the answer for each n
For example,if n=1
When k
Whenk
Whenk
Whenk
Whenk
Whenk
Whenk
Whenk
So the answer is 4.
Then T
2 1 2 2 3
3 13
代码:
#include <algorithm>
#include <cstdio>
#include <vector>
#include <iostream>
using namespace std;
const int mod = 1000000007;
int n,m;
long long quickmod(long long a,long long b)
{
long long ans = 1;
while(b)//用一个循环从右到左便利b的所有二进制位
{
if(b&1)//判断此时b[i]的二进制位是否为1
{
ans = (ans*a)%mod;//乘到结果上,这里a是a^(2^i)%m
b--;//把该为变0
}
b/=2;
a = a*a%mod;
}
return ans;
}
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n>>m;
cout<<(long long)((quickmod(m,n+1)-1)%mod*(quickmod(m-1,mod-2)%mod))%mod<<endl;
}
return 0;
}
657




被折叠的 条评论
为什么被折叠?



