2017多校训练Contest2: 1006 Funny Function hdu6050

本文介绍了一种计算特定函数Fm,1值的方法,该函数满足一定递推关系,针对给定的大整数N和M,通过快速幂运算求解该函数模1e9+7的结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



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

推导如下

F1i=2^i-(-1)^i/3
Fij=F(i+n)-F(i)
Fm1=sum(C(m-1,i)*2^i*(-1)^(m-1-i))
=(2*(2^n-1)^(m-1)+n%2)/3

#include<map>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<cassert>
#include<iostream>
#include<algorithm>
using namespace std;
long long mod=1000000007;
inline long long power(long long x,long long y)
{
	long long t=1;
	while(y!=0)
	{
		if(y%2==1)
			t=t*x%mod;
		x=x*x%mod;
		y/=2;
	}
	return t;
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T>0)
	{
		T--;
		long long n,m;
		scanf("%lld%lld",&n,&m);
		long long ans=power(2,n)-1LL;
		ans=power(ans,m-1);
		ans=ans*2LL%mod;
		ans+=n%2;
		long long xt=power(3,mod-2);
		ans=ans*xt%mod;
		printf("%lld\n",ans);
	}
	return 0;
}




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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值