HDU 6050 Funny Function
来源:互联网 发布:淘宝开店考试题 编辑:程序博客网 时间:2024/05/01 15:36
Funny Function
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 287 Accepted Submission(s): 122
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
Recommend
liuyiding
看到Fn=Fn-1+2*Fn-2,就想到类斐波那契数列,再想到特征根方程。
即两特征根方程为:x^2=x+2
解得x1=2,x2=-1.
Fn=ax1^n+bx2^n.
根据F1=F2=1,
解得Fn=2^n/3-(-1)^n/3.
接下来根据性质三,
不难得出F(m,1)通项为:
F(m,1)=(2*(2^n-1)^(m-1)+(1-(-1)^n)/2)/3。
比赛前并没接触过除法的模除,
可惜了,晒上赛后补题代码。
/*answered by Asmire*/#include <iostream>#include <stdio.h>#include <string>#include <cmath>using namespace std;typedef long long ll;const int mod = 1e9+7;ll quick_pow(ll a,ll b,ll m){ ll ans=1; while(b) { if(b&1){ ans=ans*a%m; } b=b>>1; a=a*a%m; } return ans;}void exgcd(ll a,ll b,ll &x,ll &y){ ll temp; if(!b){ x=1;y=0; return ; } exgcd(b,a%b,x,y); temp=x; x=y; y=temp-a/b*y;}int main(){ int T; ll n,m; ll x,y; ll cnt1,tmp; scanf("%d",&T); while(T--){ scanf("%I64d %I64d",&n,&m); cnt1=(quick_pow(2,n,mod)-1)%mod; tmp=quick_pow(cnt1,m-1,mod)*2%mod; exgcd(3,mod,x,y); ll k=x; if(n%2==0) printf("%I64d\n",tmp*k%mod); else printf("%I64d\n",(tmp+1)*k%mod); } return 0;}
阅读全文
3 0
- 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】 + 数学
- 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 6050Funny Function矩阵快速幂
- python中字符串的常用用法汇总
- Java容器集合类的区别用法
- 判断字符串中每个字符是否唯一出现
- 如何建立项目变更控制程序 技能点十
- 字符串转化为float类型
- HDU 6050 Funny Function
- HDU-6053 TrickGCD
- 洛阳hp:上课第二天
- IIS与.NET Framework的安装顺序问题
- 在windows中连接到虚拟机Linux的mysql
- 与服务器进行数据Android--->servlet(get、post、AsyncClient)三种方式
- intellj idea 自定义插件安装及使用
- 抽象类、接口、内部类和单例的总结!
- uva 10391 Compound Words