标签:图片 代码 lin 解法 mod csdn blog mat height
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define ll long long #define rg register using namespace std; const int mod = 1e9+7; ll n; ll a[101][101],b[101][101]; ll ans[101][101]; inline void matrix(){ memcpy(b,ans,sizeof(ans)); memset(ans,0,sizeof(ans)); for(rg int k=1;k<=2;++k) for(rg int i=1;i<=2;++i) for(rg int j=1;j<=2;++j) ans[i][j]=(ans[i][j]+(b[i][k]*a[k][j])%mod)%mod; } inline void matrix_(){ memset(b,0,sizeof(b)); for(rg int k=1;k<=2;++k) for(rg int i=1;i<=2;++i) for(rg int j=1;j<=2;++j) b[i][j]=(b[i][j]+(a[i][k]*a[k][j])%mod)%mod; memcpy(a,b,sizeof(b)); } inline void matrix_ksm(ll bas){ while(bas){ if(bas&1) matrix(); matrix_(); bas>>=1; } } int main() { scanf("%lld",&n); a[1][1]=a[1][2]=a[2][1]=1; ans[1][1]=ans[2][2]=1; matrix_ksm(n); printf("%lld",ans[2][1]); return 0; }
标签:图片 代码 lin 解法 mod csdn blog mat height
原文地址:https://www.cnblogs.com/nnezgy/p/11515503.html