【HDU 6050 Funny Function】 + 数学

Funny Function

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

Problem Description
Function Fx,ysatisfies:

这里写图片描述

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

数学大佬都是推公式的~
F(m,1)=( 2 * k ^ (m - 1)+(1+ (-1) ^ (n + 1)) / 2) / 3 ,k = (2 ^ n -1);

AC代码:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAX = 1e5 + 10;
const int mod = 1e9 + 7;
typedef long long LL;
LL km(LL a,LL b){
    LL ans = 1;
    while(b){
        if(b & 1) ans = (ans * a) % mod;
        b >>= 1; a = (a * a) % mod;
    }
    return ans;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--){
        LL n,m;
        scanf("%lld %lld",&n,&m);
        LL k = (km(2,n) - 1 + mod) % mod;
        LL k1 = (km(k,m - 1) * 2) % mod;
        LL k2 = (1 + km(-1,n + 1)) * km(2,mod - 2);
        printf("%lld\n",((k1 + k2) % mod * km(3,mod - 2)) % mod);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值