From 3e421f198cd636e5dc31ac82723f01c15836b899 Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Tue, 19 Aug 2025 12:05:27 +0800 Subject: [PATCH] update --- src/8/19/P1962.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/8/19/P1962.cpp diff --git a/src/8/19/P1962.cpp b/src/8/19/P1962.cpp new file mode 100644 index 0000000..436d9ed --- /dev/null +++ b/src/8/19/P1962.cpp @@ -0,0 +1,51 @@ +#include +#include +#include + +using ll = int64_t; + +const ll M = 1e9+7; + +struct M22{ + std::vector> v{2,std::vector(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'; +} \ No newline at end of file