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.
⋅ 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 )
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;
}