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
| #include <bits/stdc++.h> #include<stdint.h> #define int long long #define scan(n) scanf("%lld", &(n)) #define scann(n, m) scanf("%lld%lld", &(n), &(m)) #define scannn(a, b, c) scanf("%lld%lld%lld", &(a), &(b), &(c)) #define pb push_back #define fo(i, a, b) for (int i = (a); i <= (b); i++) const int N=8; using namespace std; const int mod=2147493647; struct matrix{int m[10][10];}; matrix ans,base,m; int n,a,b; matrix multi(matrix a, matrix b){ matrix tmp; for(int i=1;i<=N;++i){ for (int j=1;j<=N;++j){ tmp.m[i][j]=0; for(int k=1;k<=N;++k) tmp.m[i][j]=(tmp.m[i][j]+(a.m[i][k]*b.m[k][j]))%mod; } } return tmp; } matrix fastm(matrix base, int n){ matrix ans; memset(ans.m,0,sizeof(ans.m)); for (int i=1;i<=N;i++)ans.m[i][i]=1; while(n){ if(n&1)ans=multi(ans,base); base=multi(base, base); n>>=1; } return ans; } int32_t main(){ matrix m,ans; memset(m.m,0,sizeof(m.m)); m.m[1][1]=1;m.m[1][2]=2;m.m[1][4]=1;m.m[1][5]=4;m.m[1][6]=6;m.m[1][7]=4;m.m[1][8]=1; m.m[2][1]=1; m.m[3][2]=1; m.m[4][4]=1;m.m[4][5]=4;m.m[4][6]=6;m.m[4][7]=4;m.m[4][8]=1; m.m[5][5]=1;m.m[5][6]=3;m.m[5][7]=3;m.m[5][8]=1; m.m[6][6]=1;m.m[6][7]=2;m.m[6][8]=1; m.m[7][7]=1;m.m[7][8]=1; m.m[8][8]=1; int T;scan(T); while(T--){ scannn(n,a,b); ans = fastm(m,n-3); int f[10],x=0; f[3]=a,f[2]=b,f[1]=(2*a+b+3*3*3*3),f[4]=3*3*3*3,f[5]=3*3*3,f[6]=3*3,f[7]=3,f[8]=1; fo(i,1,8){ x=x%mod+((f[i]%mod)*(ans.m[1][i])%mod)%mod; x%=mod; } printf("%lld\n",x); } return 0;
|