[ustctraining][13.05.09]E - 特殊的数
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> using namespace std; #define FOR(i,a,b) for(int i=a;i<=b;i++) #define MST(a,b) memset(a,b,sizeof(a)) #define MOD 1000000007 int main() { freopen("in.txt","r",stdin); int nn; scanf("%d",&nn); FOR(ii,1,nn) { long long n; cin>>n; long long a0[3][3]; MST(a0,0); FOR(i,0,2)a0[i][i]=3; a0[0][1]=1; a0[1][0]=2; a0[2][1]=1; a0[1][2]=2; long long c[3][3],b[3][3]; MST(c,0); FOR(i,0,2)c[i][i]=1; FOR(i,0,2)FOR(j,0,2)b[i][j]=a0[i][j]; long long p=1; while(n) { if(1&n) { long long c0[3][3]; FOR(i,0,2)FOR(j,0,2)c0[i][j]=c[i][j]; MST(c,0); FOR(k,0,2)FOR(i,0,2)FOR(j,0,2)c[i][j]=(c[i][j]+c0[i][k]*b[k][j])%MOD; } n=n>>1; long long b0[3][3]; FOR(i,0,2)FOR(j,0,2)b0[i][j]=b[i][j]; MST(b,0); FOR(k,0,2)FOR(i,0,2)FOR(j,0,2)b[i][j]=(b[i][j]+b0[i][k]*b0[k][j])%MOD; } long long f0[3],f[3]; MST(f0,0); MST(f,0); f0[0]=1; FOR(k,0,2)FOR(j,0,2)f[j]=(f[j]+f0[k]*c[k][j])%MOD; printf("%d\n",f[0]); } }