hdu 6050 Funny Function(快速幂)
来源:互联网 发布:北京超图软件 编辑:程序博客网 时间:2024/05/22 00:31
Funny Function
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1210 Accepted Submission(s): 592
Problem Description
Function Fx,y satisfies:
For given integers N and M,calculateFm,1 modulo 1e9+7.
For given integers N and M,calculate
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
22 23 3
Sample Output
233
暴力打表枚举比较小的n, m的最后结果,找到规律
ans=⎧⎩⎨2(2n−1)m−13,2(2n−1)m−1+13,n & 1 == 0n & 1 == 1
赛场上看到这道题,能勇敢的去这么做的真的需要勇气
由于公式还涉及到除法,所以可能需要更多一点的时间
#include<iostream>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include<vector>#include<map>#include <bits/stdc++.h>using namespace std;const int N = 1100000+10;typedef long long LL;const LL mod = 1e9+7;char str[N];stack<LL>st;LL cal(LL x,LL n){ LL r=1; while(n) { if(n&1) r=r*x%mod; n>>=1; x=x*x%mod; } return r;}int main(){ int t; scanf("%d", &t); while(t--) { LL n, m; scanf("%lld %lld", &n, &m); if((n&1)==0) { printf("%lld\n",(2*cal((cal(2,n)-1),m-1))*cal(3,mod-2)%mod); } else { printf("%lld\n",(2*cal((cal(2,n)-1),m-1)+1)*cal(3,mod-2)%mod); } } return 0;}
ans=⎧⎩⎨2(2n−1)m−13,2(2n−1)m−1+13,n & 1 == 0n & 1 == 1
阅读全文
0 0
- HDU 6050 Funny Function 矩阵快速幂
- HDU 6050 Funny Function(快速幂)
- hdu 6050 Funny Function(快速幂)
- hdu 6050Funny Function矩阵快速幂
- (矩阵快速幂, 数学公式推导)HDU 6050 Funny Function
- hdu 6050 Funny Function (数学题+快速幂)
- hdu 6050 Funny Function (矩阵快速幂)
- HDU 6050 Funny Function【乘法逆元+快速幂】
- HDU 6050 Funny Function(矩阵快速幂或公式)
- HDU 6050 Funny Function
- hdu 6050 Funny Function
- hdu 6050 funny function
- HDU-6050 Funny Function
- HDU 6050 Funny Function
- HDU 6050 Funny Function
- HDU 6050 Funny Function
- HDU 6050 Funny Function
- hdu 6050 Funny Function
- [J
- 缓冲输出流写出数据的缓冲区问题
- 从HDFS上读取带lzo压缩的SequenceFile文件
- 杭电oj1096 加法 注意输出格式
- 1000
- hdu 6050 Funny Function(快速幂)
- 欢迎使用CSDN-个人第一个CSDN博客
- 1091. Acute Stroke (30)三维广搜
- Birthday Paradox(生日悖论)
- POJ
- 用for循环打印菱形
- bzoj3517: 翻硬币
- [LeetCode] 111. Minimum Depth of Binary Tree
- 幸福的道路(race)