样例没过!求救!
查看原帖
样例没过!求救!
712941
zyl0128_alpha楼主2022/10/14 23:08
#include<bits/stdc++.h>
using namespace std;
struct Matrix{
	long long c[3][3];
}A,res;
long long n;
const int mod=1e9+7;
Matrix chengfa(Matrix &x,Matrix &y){
	//[Fn-1 Fn-2]*[1 1]=[Fn Fn-1]
	//			  [1 0]
	Matrix t;
	memset(t.c,0,sizeof(t.c));
	for(int i=1;i<=2;i++){
		for(int j=1;j<=2;j++){
			for(int k=1;k<=2;k++){
				t.c[i][j]=(t.c[i][j]+(x.c[i][k]*y.c[k][j])%mod)%mod;
			}
		}
	}
	return t;
}
void init(){
	A.c[1][1]=A.c[1][2]=A.c[2][1]=0;
	res.c[1][1]=res.c[1][2]=1;	
}
void pow(int n){	
	while(n){
		if(n&1){
			res=chengfa(res,A);
		}
		A=chengfa(A,A);
		n>>=1;
	}
}
int main(){
	cin>>n;
	if(n<=2){
		cout<<1;
	}else{
		init();
		pow(n-2);
	}
	cout<<res.c[1][1]%mod;
	return 0;
}
2022/10/14 23:08
加载中...