【2017沈阳网络赛】1005 hdu6198 number number number 找规律+矩阵快速幂
2017-09-11 11:22
483 查看
Problem Description
We define a sequence F:
⋅ F0=0,F1=1;
⋅ Fn=Fn−1+Fn−2 (n≥2).
Give you an integer k,
if a positive number n can
be expressed by
n=Fa1+Fa2+...+Fak where 0≤a1≤a2≤⋯≤ak,
this positive number is mjf−good.
Otherwise, this positive number is mjf−bad.
Now, give you an integer k,
you task is to find the minimal positive mjf−bad number.
The answer may be too large. Please print the answer modulo 998244353.
Input
There are about 500 test cases, end up with EOF.
Each test case includes an integer k which
is described above. (1≤k≤109)
Output
For each case, output the minimal mjf−bad number
mod 998244353.
Sample Input
1
Sample Output
4
题意:
给出一个数k,问用k个斐波那契数相加,得不到的数最小是几。
思路:
找规律发现,答案就是f(2*k+3)-1,用矩阵快速幂求即可。
We define a sequence F:
⋅ F0=0,F1=1;
⋅ Fn=Fn−1+Fn−2 (n≥2).
Give you an integer k,
if a positive number n can
be expressed by
n=Fa1+Fa2+...+Fak where 0≤a1≤a2≤⋯≤ak,
this positive number is mjf−good.
Otherwise, this positive number is mjf−bad.
Now, give you an integer k,
you task is to find the minimal positive mjf−bad number.
The answer may be too large. Please print the answer modulo 998244353.
Input
There are about 500 test cases, end up with EOF.
Each test case includes an integer k which
is described above. (1≤k≤109)
Output
For each case, output the minimal mjf−bad number
mod 998244353.
Sample Input
1
Sample Output
4
题意:
给出一个数k,问用k个斐波那契数相加,得不到的数最小是几。
思路:
找规律发现,答案就是f(2*k+3)-1,用矩阵快速幂求即可。
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> using namespace std; typedef long long LL; const LL Mod = 998244353; class Matrix{ //阶数为n public: LL p[2][2]; Matrix(){ memset(p,0,sizeof(p)); p[0][0]=1; p[1][1]=1; } Matrix mul(Matrix x,Matrix y){ Matrix c; memset(c.p,0,sizeof(c.p)); for(int i=0;i<2;i++) for(int j=0;j<2;j++){ for(int k=0;k<2;k++){ c.p[i][j]+=(x.p[i][k]*y.p[k][j])%Mod; c.p[i][j]%=Mod; } } return c; } Matrix pow(Matrix x,LL n){ Matrix ans,p=x; while(n){ if(n&1) ans=ans.mul(ans,p); p=p.mul(p,p); n>>=1; } return ans; } }; int main(int argc,const char*argv[]){ LL k; while(scanf("%lld",&k)!=EOF){ LL n=2*k+3; Matrix x; Matrix y; memset(x.p,0,sizeof(x.p)); memset(y.p,0,sizeof(y.p)); x.p[0][0]=1; x.p[0][1]=1; x.p[1][0]=1; y.p[0][0]=1; y.p[1][0]=0; x=x.pow(x,n-1); x=x.mul(x,y); cout<<x.p[0][0]-1<<endl; } return 0; }
相关文章推荐
- 【HDU6198 2017 ACM ICPC Asia Regional Shenyang Online E】【找规律 + 矩阵快速幂 + 粗略证明】number number number 无法用K
- HDU - 6198 number number number (2017 ACM-ICPC 亚洲区 (沈阳赛区) 网络赛 1005)
- hdu6198 number number number【找规律+矩阵快速幂】
- hdu6198 number number number(找规律+矩阵快速幂)
- hdu6198 17沈阳网络赛 矩阵快速幂
- 2017 ACM/ICPC Asia Regional Shenyang Online 1005 number number number(矩阵快速幂)
- 2017 icpc 沈阳赛区 1005.number number number(矩阵快速幂)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛b题Coin(矩阵快速幂)
- Number Sequence HDU - 1005 (矩阵快速幂)
- 2017 Multi-University Training Contest 10 1002 Array Challenge HDU 6172(找规律 矩阵快速幂)
- 2017 ACM/ICPC Asia Regional Shenyang Online 1005 & hdu6198:number number number
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Coin 矩阵快速幂
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Coin 概率+矩阵快速幂
- 【HDU 6198】number number number 【规律+矩阵快速幂】
- 【打表找规律+矩阵快速幂】number number number HDU - 6198
- 2017 ACM/ICPC Asia Regional Shenyang Online E题【number number number】--矩阵快速幂与斐波那契数列
- hdu6198 number number number(矩阵快速幂模板题)
- 打表找规律+矩阵快速幂 - hdu6198
- HDU6198 number number number 矩阵快速幂
- HDU-6198 number number number(打表找规律、矩阵快速幂)