number number number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 132 Accepted Submission(s): 90
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
Source
——————————————————————————————————
题目的意思是在斐波那契序列中找出k个数从凑出的数是good的,不能就是bad的,给出k,求最小的bad数
思路:找规律发现这个数是斐波那契第2*k+3项-1,数据较大矩阵快速幂搞定
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
#define LL long long
const int INF = 0x3f3f3f3f;
const LL mod=998244353;
struct Matrix
{
LL v[5][5];
Matrix()
{
memset(v,0,sizeof v);
}
} dan;
Matrix mul(Matrix a,Matrix b,int d)
{
Matrix ans;
for(int i=0; i<d; i++)
{
for(int j=0; j<d; j++)
{
for(int k=0; k<d; k++)
{
ans.v[i][j]+=(a.v[i][k]*b.v[k][j])%mod;
ans.v[i][j]%=mod;
}
}
}
return ans;
}
Matrix pow(Matrix a,int k,int d)
{
Matrix ans=dan;
while(k)
{
if(k&1) ans=mul(ans,a,d);
k>>=1;
a=mul(a,a,d);
}
return ans;
}
int main()
{
int k;
while(~scanf("%d",&k))
{
dan.v[0][0]=1,dan.v[0][1]=0;
Matrix a;
a.v[0][0]=a.v[0][1]=a.v[1][0]=1,a.v[1][1]=0;
Matrix ans= pow(a,2*k+2,2);
printf("%lld\n",((ans.v[0][0]-1)%mod+mod)%mod);
}
return 0;
}