hdu6050Funny Function(快速幂,高校2)
来源:互联网 发布:省市区json数据 编辑:程序博客网 时间:2024/06/09 18:39
Funny Function
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1224 Accepted Submission(s): 604
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
Source
2017 Multi-University Training Contest - Team 2
题意:给你,n,m,求出f(m,1),
由公式推出通项公式:
n为偶数时F(m,1)=2*(2^n-1)^(m-1)/3
n为奇数时F(m,1)=(2*(2^n-1)^(m-1)+1)/3
n为奇数时F(m,1)=(2*(2^n-1)^(m-1)+1)/3
由于指数较大,用快速幂
#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <queue>#include <iostream>#define LL unsigned long long#define inf 0x3f3f3f3f#define mod 1000000007using namespace std;LL pow3(LL a,LL b)///a的b次方取余r{ a%=mod; if(a==0) return 0; LL ans = 1,base = a; while(b) { if(b&1)//奇数时 ans = (ans*base)%mod; base= (base*base)%mod; b>>=1; } return ans;}int main(){ int t; LL n,m,ans; scanf("%d",&t); while(t--) { scanf("%lld %lld",&n,&m); if(n%2==0) ans=(2*pow3((pow3(2,n)-1)%mod,m-1))*333333336%mod; else ans=(2*pow3((pow3(2,n)-1)%mod,m-1)+1)*333333336%mod; cout<<ans%mod<<endl; } return 0;}
阅读全文
0 0
- hdu6050Funny Function(快速幂,高校2)
- HDU6050Funny Function
- codeforces_678D. Iterated Linear Function(快速幂)
- HDU6050 Funny Function[矩阵快速幂]
- HDU 6050 Funny Function 矩阵快速幂
- HDU 6050 Funny Function(快速幂)
- hdu 6050 Funny Function(快速幂)
- hdu 6050Funny Function矩阵快速幂
- 2017 Multi-University Training Contest 2 && HDOJ 6050 Funny Function 【思维+快速幂】
- 热血高校2
- 高校
- CodeForces 678D Iterated Linear Function 矩阵快速幂
- (矩阵快速幂, 数学公式推导)HDU 6050 Funny Function
- hdu6050 Funny Function【打表+找规律+矩阵快速幂】
- hdu 6050 Funny Function (数学题+快速幂)
- hdu 6050 Funny Function (矩阵快速幂)
- HDU 6050 Funny Function【乘法逆元+快速幂】
- HDU 6050 Funny Function(矩阵快速幂或公式)
- RXD's date(HDU 6066)
- .net 序列化
- jdbc
- linux桥处理的一点理解
- R-CNN-目标检测、定位、分割
- hdu6050Funny Function(快速幂,高校2)
- Loadrunner 性能指标定位系统瓶颈
- 8.1--集训日记--搜索+练习赛
- 2017多校联合三/hdu6066RXD's date大水题
- CSDN添加自定义博客栏目(没接触过的让我带你走进一个神奇的世界)
- 函数
- spring boot 发送邮件
- hdu 6058 Kanade's sum(模拟)
- ajax+fastJson 对象传输