number number number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 99 Accepted Submission(s): 64
Problem Description
We define a sequence
F
:
⋅
F
0
=0,F
1
=1
;
⋅
F
n
=F
n−1
+F
n−2
(n≥2)
.
Give you an integer k
, if a positive number
n
can be expressed by
n=F
a
1![]()
+F
a
2![]()
+...+F
a
k![]()
![]()
where
0≤a
1
≤a
2
≤⋯≤a
k![]()
, 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.
⋅
⋅
Give you an integer k
n=F
Now, give you an integer k
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≤10
9![]()
)
Each test case includes an integer k
Output
For each case, output the minimal
mjf−bad
number mod 998244353.
Sample Input
1
Sample Output
4
Source
Recommend
liuyiding
矩阵快速幂,通过计算发现前几组数据是4,12,33,88等
代码如下:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
typedef long long ll;
struct Matrix{
ll matrix[5][5];
};
int n;//矩阵的阶数
const int mod=998244353;
void init(Matrix &res)
{
memset(res.matrix,0,sizeof(res.matrix));
for(int i=0;i<n;i++)
res.matrix[i][i]=1;
}
Matrix multiplicative(Matrix a,Matrix b)
{
Matrix res;
for(int i = 0 ; i < n ; i++){
for(int j = 0 ; j < n ; j++){
res.matrix[i][j]=0;
for(int k = 0 ; k < n ; k++){
res.matrix[i][j] = (res.matrix[i][j]%mod+a.matrix[i][k]*b.matrix[k][j]%mod)%mod;
}
}
}
return res;
}
Matrix pow(Matrix mx,ll m)
{
Matrix res,base=mx;
init(res);
while(m)
{
if(m&1)
res=multiplicative(res,base);
base=multiplicative(base,base);
m>>=1;
}
return res;
}
int main()
{
Matrix mx,nx;
ll m,ans;
ll k;
while(~scanf("%lld",&k))
{
n=2;
m=2*k+4;
mx.matrix[0][0]=mx.matrix[0][1]=mx.matrix[1][0]=1;
mx.matrix[1][1]=0;
nx=pow(mx,m-1);
ans=(nx.matrix[0][0]*0+nx.matrix[0][1]*1)%mod;
if(ans==0)
printf("%lld\n",mod-1);
else
printf("%lld\n",ans-1);
}
return 0;
}