题目:
题意:判断长度为k的斐波那契数列不能组成的最小正数是多少。每个斐波那契元素可以选取任意次数
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=1时,不能组成的最小正数是4,2的时候是12,3的时候是33,4的时候是88.由于题目输入数据较大,可知一定存在着某种规律。易发现k=1的时候答案
为斐波那契数列下标为5的值减1,2的时候为下标为7的值减1,3的时候下标为9的值减1......所以答案为fabo(3+n*2)%mod-1
code:
#include<bits/stdc++.h>
using namespace std;
const int MOD=998244353;
struct matrix
{
__int64 m[2][2];
}ans, base;
matrix multi(matrix a, matrix b)
{
matrix tmp;
for(int i = 0; i < 2; ++i)
{
for(int j = 0; j < 2; ++j)
{
tmp.m[i][j] = 0;
for(int k = 0; k < 2; ++k)
tmp.m[i][j] = (tmp.m[i][j] + ( a.m[i][k] * b.m[k][j]) % MOD ) %MOD;
}
}
return tmp;
}
__int64 fast_mod(__int64 n)
{
base.m[0][0] = base.m[0][1] = base.m[1][0] = 1;
base.m[1][1] = 0;
ans.m[0][0] = ans.m[1][1] = 1;
ans.m[0][1] = ans.m[1][0] = 0;
while(n)
{
if(n & 1) ans = multi(ans, base);
base = multi(base, base);
n >>= 1;
}
return ans.m[0][1]%MOD;
}
int main()
{
__int64 n;
while(~scanf("%I64d",&n)){
n=3+n*2;
printf("%I64d\n",fast_mod(n)-1);
}
return 0;
}