Funny Function
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1082 Accepted Submission(s): 513
Problem Description
Function
F
x,y![]()
satisfies:
For given integers N and M,calculate F
m,1![]()
modulo 1e9+7.

For given integers N and M,calculate F
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.
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
这道题可以根据题目给的公式打表,再结合特征根法以及等比等差求和公式来得到最后的公式。 n为奇数 ans=((2*(2^n-1))^(m-1)+1)/3 n为偶数 ans=((2*(2^n-1))^(m-1))/3
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<cstdio>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<functional>
#include<iostream>
#include<algorithm>
using namespace std;
const long long int MOD=7+1e9;
long long int poww(long long int x,long long int y)
{
long long int ans=1;
while(y)
{
if(y&1)ans=ans*x%MOD;
x=x*x%MOD;
y>>=1;
}
return ans%MOD;
}
int main(){
int t;
cin>>t;
while(t--)
{
long long int n,m;
cin>>n>>m;
long long int ans;
if(n%2==1)
ans=(2*poww(poww(2,n)-1,m-1)%MOD+1)%MOD*poww(3,MOD-2)%MOD;
else ans=((2*poww(poww(2,n)-1,m-1))%MOD)*poww(3,MOD-2)%MOD;
cout<<ans%MOD<<endl;
}
return 0;
}