2017多校训练Contest2: 1006 Funny Function hdu6050
来源:互联网 发布:ubuntu版本查看命令 编辑:程序博客网 时间:2024/06/05 20:59
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
推导如下
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,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
阅读全文
0 0
- 2017多校训练Contest2: 1006 Funny Function hdu6050
- 2017多校训练第二场 hdu6050 Funny Function(数学+快速幂+逆元)
- HDU-2017 多校训练赛2-1006-Funny Function
- 2017 多校训练第二场 HDU 6050 Funny Function
- 2017多校训练Contest2: 1001 Captain is coding hdu6045
- 2017多校训练Contest2: 1003 Maximum Sequence hdu6047
- 2017多校训练Contest2: 1009 TrickGCD hdu6053
- 2017多校训练Contest2: 1011 Regular polygon hdu6055
- HDU6050-Funny Function
- HDU6050-Funny Function
- Hdu6050 Funny Function(2017多校第2场)
- HDU-2017 多校训练赛1-1006-Function
- HDU6050 Funny Function[矩阵快速幂]
- 2017 多校训练第一场 HDU 6038 Function
- 2017杭电多校联赛第二场-Funny Function (hdu6050)快速幂解数学方程
- HDU 6038 (2017 多校训练赛1 1006) Function(图论)
- hdu6050 Funny Function【打表+找规律+矩阵快速幂】
- 2017多校训练Contest5: 1006 Rikka with Graph hdu6090
- Java异常处理
- 初识editableGrid 控件
- 新零售核心是大数据驱动的线上线下融合
- 五、迭代器--迭代器辅助函数
- awk基本手册汇总
- 2017多校训练Contest2: 1006 Funny Function hdu6050
- memcached全面剖析–5. memcached的应用和兼容程序
- Python函数
- HDU 1150 Machine Schedule
- \r\n的意义
- 13.5 动态内存管理类
- ssh免登录
- 简述 OAuth 2.0 的运作流程
- ocr识别验证码