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;
}