hdu6050



Funny Function

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 657    Accepted Submission(s): 299


Problem Description
Function  Fx,y satisfies:

For given integers N and M,calculate  Fm,1  modulo 1e9+7.
 

Input
There is one integer T in the first line.
The next T lines,each line includes two integers N and M .
1<=T<=10000,1<=N,M<2^63.
 

Output
For each given N and M,print the answer in a single line.
 

Sample Input
      
      
2 2 2 3 3
 

Sample Output
      
      
2 33
思路:可以根据数学归纳法推出公式,主要会出现除数,所以需要用到除法取模。
代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
const int MOD=1e9+7;
vector<int>a1;
vector<int>a2;
int v[100005];
int x[3005],y[3005];
int ma[2055][2055];
long long int poww(long long int m,long long int n)
{
    long long int x=1;
    while(n)
    {
        if(n&1)x=(x*m)%MOD;
        m=(m*m)%MOD;
        n>>=1;
    }
    return x;
}
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        long long int m,n;
        scanf("%lld %lld",&m,&n);
        long long int ans;
        if(m%2==0)
        {
            ans=(((2*poww((poww(2,m)-1),n-1))%MOD)*poww(3,MOD-2))%MOD;
        }
        else
        {
            ans=(((2*poww((poww(2,m)-1),n-1)+1)%MOD)*poww(3,MOD-2))%MOD;
        }
        cout<<ans<<endl;
    }
    return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值