2017多校训练Contest2: 1006 Funny Function hdu6050

来源:互联网 发布:ubuntu版本查看命令 编辑:程序博客网 时间:2024/06/05 20:59



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
22 23 3
 

Sample Output
233

推导如下

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
22 23 3
 

Sample Output
233