版权声明:欢迎大家指正错误,有不同观点的欢迎评论,共同进步 https://blog.csdn.net/Sirius_han/article/details/81950641
number number number
题意:找出不能由k个斐波那契数构成的最小数;
打表找规律,发现结果是第2*k+2个斐波那契数-1
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
struct node{
ll x[2][2];
};
node mul(node a, node b){
node c;
for(int i=0; i<2; i++){
for(int j=0; j<2; j++){
c.x[i][j]=0;
}
}
for(int i=0; i<2; i++){
for(int j=0; j<2; j++){
for(int k=0; k<2; k++){
c.x[i][j]=(c.x[i][j]+a.x[i][k]*b.x[k][j]%mod)%mod;
}
}
}
return c;
}
ll pow_m(node a, int b){
node ans;
memset(ans.x, 0, sizeof(ans.x));
for(int i=0; i<2; i++){
ans.x[i][i]=1;
}
while(b){
if(b&1){
ans=mul(ans, a);
}
b>>=1;
a=mul(a, a);
}
return (ans.x[0][0]*1+ans.x[1][1]*0)%mod;
}
int main(){
int k;
while(~scanf("%d", &k)){
node a;
a.x[0][0]=a.x[0][1]=a.x[1][0]=1;
a.x[1][1]=0;
int n=2*k+2;
ll ans=pow_m(a, n);
printf("%lld\n", (ans-1+mod)%mod);
}
return 0;
}