This commit is contained in:
Zengtudor 2025-08-19 12:05:27 +08:00
parent 321c58cc95
commit 3e421f198c

51
src/8/19/P1962.cpp Normal file
View File

@ -0,0 +1,51 @@
#include <cstdint>
#include <iostream>
#include <vector>
using ll = int64_t;
const ll M = 1e9+7;
struct M22{
std::vector<std::vector<ll>> v{2,std::vector<ll>(2)};
M22 operator*(const M22&o){
M22 n;
n.v[0][0]=(v[0][0]*o.v[0][0]%M+v[0][1]*o.v[1][0]%M)%M;
n.v[0][1]=(v[0][0]*o.v[0][1]%M+v[0][1]*o.v[1][1]%M)%M;
n.v[1][0]=(v[1][0]*o.v[0][0]%M+v[1][1]*o.v[1][0]%M)%M;
n.v[1][1]=(v[1][0]*o.v[0][1]%M+v[1][1]*o.v[1][1]%M)%M;
return n;
}
M22&operator*=(const M22&o){
*this= *this * o;
return *this;
}
};
M22 fpow(M22 b,ll e){
M22 res;
res.v[0][0]=res.v[1][1]=1;
while(e){
if(e&1){
res*=b;
}
b*=b;
e>>=1;
}
return res;
}
int main(){
ll n;
std::cin>>n;
if(n<=2){
std::cout<<1<<'\n';
return 0;
}
n-=2;
M22 m{{{1,1},{1,0}}};
m=fpow(m, n);
std::cout<<
(m.v[0][0]+m.v[0][1])%M
<<'\n';
}