HDU 6050 Funny Function(快速幂)
来源:互联网 发布:手机音乐可视化软件 编辑:程序博客网 时间:2024/05/22 04:41
Description
函数F(x,y)满足:
给出n,m,求F(m,1)%1e9+7
Input
第一行一整数T表示用例组数,每组用例输入两个整数n,m (1<=T<=1e4,1<=n,m < 2^63)
Output
对于每组用例,输出F(m,1)%1e9+7
Sample Input
2
2 2
3 3
Sample Output
2
33
Solution
Code
#include<cstdio>using namespace std;typedef long long ll;const int mod=1000000007,inv3=333333336;int T;ll n,m;int mod_pow(int a,int b){ int ans=1; while(b) { if(b&1)ans=(ll)ans*a%mod; a=(ll)a*a%mod; b>>=1; } return ans;}int main(){ scanf("%d",&T); while(T--) { scanf("%I64d%I64d",&n,&m); if(m==1) { printf("1\n"); continue; } int ans=0; int a=mod_pow(2,n%(mod-1))-1; ans=(ans+2ll*mod_pow(a,(m-1)%(mod-1)))%mod; if(n&1)ans++; if(ans>=mod)ans-=mod; ans=(ll)ans*inv3%mod; printf("%d\n",ans); } return 0;}
阅读全文
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(矩阵快速幂或公式)
- Funny Function(HDU 6050)
- 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
- CSS3基础知识
- MyBatis之XML文件配置实现映射器Mapper
- 虚拟机克隆
- 运算符的重载
- 54. Spiral Matrix
- HDU 6050 Funny Function(快速幂)
- IPC之信号编程(2)
- 机器学习第三周(一)--逻辑回归引入
- 个人java学习回顾01
- dubbo源码深度解读三之container模块
- 面试---算法排序(3)(希尔排序)
- js 之 prototype原型 理解
- 8. String to Integer (atoi)
- word转pdf