1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| #include<iostream> #include<cstring> #define min(a,b) ((a)>(b)?(b):(a)) #define max(a,b) ((a)<(b)?(b):(a)) using namespace std; const long long MAXN=10,mo=1e9+7;
struct juzhen{ public: juzhen(int han,int lin){ h=han,l=lin; memset(v,0,sizeof(v)); } juzhen(){ memset(v,0,sizeof(v)); } void cleanForPow(void){ memset(v,0,sizeof(v)); int p=min(h,l); for(int i=1;i<=p;++i){ v[i][i]=1; } } friend juzhen operator *(juzhen a,juzhen b){ juzhen c(a.h,b.l); if(a.l!=b.h)return c; for(int i=1;i<=a.h;++i){ for(int j=1;j<=b.l;++j){ long long s=0; for(int k=1;k<=a.l;++k){ s=s%mo+(a.v[i][k]*b.v[k][j]%mo); } c.v[i][j]=s; } } return c; } juzhen pow(int k){ juzhen res=*this; juzhen ret(h,l); ret.cleanForPow(); while(k){ if(k&1){ ret=ret*res; } res=res*res; k>>=1; } return ret; } void setV(long long t[MAXN][MAXN]){ for(int i=1;i<=h;++i){ for(int j=1;j<=l;++j){ v[i][j]=t[i][j]; } } } long long v[MAXN][MAXN]; private: int h,l; };
int main(void){ int T; cin>>T; long long tmp[MAXN][MAXN]={{0},{0,2,1,1,1}}; long long tmp2[MAXN][MAXN]={ {0}, {0,1,1,0,0}, {0,0,0,1,0}, {0,1,0,0,1}, {0,0,0,0,0} }; juzhen a(1,4); juzhen b(4,4); a.setV(tmp); b.setV(tmp2); while(T--){ int n; cin>>n; if(n<=3)cout<<"1\n",continue; juzhen ans=a*b.pow(n-4); cout<<ans.v[1][1]<<'\n'; } return 0; }
|