题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5793
A Boring Question
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 453 Accepted Submission(s): 249
Problem Description
There are an equation.
We define that . And while .
You have to get the answer for each and that given to you.
For example,if , ,
When ;
When ;
When ;
When ;
When ;
When ;
When ;
When .
So the answer is 4.
We define that . And while .
You have to get the answer for each and that given to you.
For example,if , ,
When ;
When ;
When ;
When ;
When ;
When ;
When ;
When .
So the answer is 4.
Input
The first line of the input contains the only integer
,
Then lines follow,the i-th line contains two integers , ,
Then lines follow,the i-th line contains two integers , ,
Output
For each
and
,output the answer in a single line.
Sample Input
2 1 2 2 3
Sample Output
3 13
Author
UESTC
Source
解题思路:
(其实也可以打表找到这个规律)
详见代码。
#include <iostream>
#include <cstdio>
using namespace std;
#define ll long long
#define mod 1000000007
ll fun(ll a,ll b)
{
ll s=1;
while (b)
{
if (b%2==1)
s=s*a%mod;
a=a*a%mod;
b>>=1;
}
return s%mod;
}
int main()
{
ll t,n,m;
scanf("%lld",&t);
while (t--)
{
scanf("%lld%lld",&n,&m);
ll ans=((fun(m,n+1)-1)*fun(m-1,mod-2)%mod+mod)%mod;
printf ("%lld\n",ans);
}
}