hdu 5793 A Boring Question(2016 Multi-University Training Contest 6——快速幂取模)

题目链接: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.
 

Input
The first line of the input contains the only integer  ,
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);
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值