问题描述:
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个斐波拉契数不能组成的最小的数.
题目分析:通过自己手动模拟,我们求出当
k=1 4 F(5)-1
k=2 12 F(7)-1
k=3 33 F(9)-1
不难发现,答案就是F(5+(k-1)*2)-1 % mod,然后矩阵快速幂
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
const ll mod=998244353;
struct matrix
{
ll f[3][3];
matrix operator*(const matrix &a) const {
matrix res;
for (int i=1;i<=2;i++) {
for (int j=1;j<=2;j++) {
res.f[i][j]=0;
for (int k=1;k<=2;k++)
res.f[i][j]=(res.f[i][j]+f[i][k]*a.f[k][j]);
res.f[i][j]=(res.f[i][j]%mod+mod)%mod;
}
}
return res;
}
}a,b;
matrix fast_pow(matrix base,ll k)
{
matrix ans=base;
while (k) {
if (k&1)
ans=ans*base;
base=base*base;
k>>=1;
}
return ans;
}
void init()
{
b.f[1][1]=b.f[1][2]=1;
b.f[2][1]=1,b.f[2][2]=0;
a.f[1][1]=1;
a.f[2][1]=0;
}
int main()
{
ll k;
while (scanf("%lld",&k)!=EOF) {
k=5+(k-1)*2;
init();
struct matrix cur,ans;
cur=b;
cur=fast_pow(b,k-2);//我的矩阵写法不一样,所以减了2
ans=cur*a;
printf("%lld\n",(ans.f[1][1]-1)%mod);
}
return 0;
}