number number number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 224 Accepted Submission(s): 145
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个斐波那契数组不成的最小的数字是谁。
思路:
根据打表有前几项,然后根据前几项递推一下,有F【i】=F【i-1】*3-F【i-2】+1;
然后矩阵快速幂跑一下就行了。
Ac代码:
//F[i]=F[i-1]*3-f[i-2]+1;
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll long long int
int const mod = 998244353;
struct matrix
{
ll m[3][3];
};
matrix A,B;
matrix multiply(matrix x, matrix y) //矩阵乘法
{
matrix tmp;
memset(tmp.m, 0, sizeof(tmp.m));
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
if(x.m[i][j] == 0)
continue;
for(int k = 0; k < 3; k++)
{
if(y.m[j][k] == 0)
continue;
tmp.m[i][k] = ((tmp.m[i][k]+x.m[i][j] * y.m[j][k])%mod+mod)%mod;
}
}
}
return tmp;
}
matrix quickmod(matrix a, int n) //矩阵快速幂
{
matrix res;
memset(res.m, 0, sizeof(res.m));
for(int i = 0; i < 3; i++)
res.m[i][i] = 1;
while(n)
{
if(n & 1)
res = multiply(res, a);
n >>= 1;
a = multiply(a, a);
}
return res;
}
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(A.m,0,sizeof(A.m));
A.m[0][0]=3;A.m[0][1]=-1;A.m[0][2]=1;
A.m[1][0]=1;A.m[1][1]=0 ;A.m[1][2]=0;
A.m[2][0]=0;A.m[2][1]=0 ;A.m[2][2]=1;
B=quickmod(A,n);
ll ans=B.m[0][0]+B.m[0][2];
ans=(ans%mod+mod)%mod;
printf("%lld\n",ans);
}
}