标签:struct ret lin ace col res for style namespace
#include<bits/stdc++.h> #define ll long long #define For(i,l,r) for(int i=l;i<=r;i++) using namespace std; int T,n; const int p=1e9+7; struct mat{ ll m[5][5]; }ans,base; inline mat mul(mat a,mat b){//等我学会重载运算符我就来改!quq mat res; memset(res.m,0,sizeof(res.m)); For(i,1,3){ For(j,1,3){ For(k,1,3){ res.m[i][j]+=(a.m[i][k]%p)*(b.m[k][j]%p); res.m[i][j]%=p; } } } return res; } inline void sets(){ memset(ans.m,0,sizeof(ans.m)); For(i,1,3) ans.m[i][i]=1; memset(base.m,0,sizeof(base.m)); base.m[1][1]=base.m[1][3]=base.m[2][1]=base.m[3][2]=1; } inline void matksm(){ while(n){ if(n&1) ans=mul(ans,base); base=mul(base,base); n>>=1; } } int main(){ scanf("%d",&T); while(T--){ scanf("%d",&n); if(n<=3){printf("1\n");continue;} sets(); matksm(); printf("%lld\n",ans.m[2][1]); } return 0; }
标签:struct ret lin ace col res for style namespace
原文地址:https://www.cnblogs.com/jian-song/p/11622581.html