为什么我要写矩阵优化呢?因为我手边有一个现成代码。。。
#include<bits/stdc++.h>
using namespace std;
struct node{
int a,b,c,d;
node operator *(const node &other)const{
return {a*other.a+b*other.c,a*other.b+b*other.d,c*other.a+d*other.c,c*other.b+d*other.d};
}
};
int n;
node tmp={1,1,1,0},res={1,0,0,1};
int main(){
cin>>n;
if(n==0){
puts("0.00");
return ~~( 0 ^ 0 )+~~0;
}
if(n<=2){
puts("1.00");
return ~~( 0 ^ 0 )+~~0;
}
n-=2;
while(n){
if(n&1){
res=res*tmp;
}
tmp = tmp*tmp;
n>>=1;
}
printf("%d.00\n",res.a+res.c);
return ~~( 0 ^ 0 )+~~0;
}