话说谁能告诉我矩阵怎么用latex表示……
差不多就这样
1 //minamoto 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #define ll long long 6 using namespace std; 7 ll n,m,p,q,a1,a2; 8 struct Matrix{ 9 ll g[2][2]; 10 Matrix(){memset(g,0,sizeof(g));} 11 Matrix(int Arr[2][2]){ 12 for(int i=0;i<2;++i) for(int j=0;j<2;++j) 13 g[i][j]=Arr[i][j]; 14 } 15 inline Matrix operator *(Matrix b){ 16 Matrix ans; 17 for(int i=0;i<2;++i) 18 for(int j=0;j<2;++j) 19 for(int k=0;k<2;++k) 20 (ans.g[i][j]+=g[i][k]*b.g[k][j])%=m; 21 return ans; 22 } 23 }; 24 int main(){ 25 scanf("%lld%lld%lld%lld%lld%lld",&p,&q,&a1,&a2,&n,&m); 26 if(n==1) return printf("%lld ",a1),0; 27 if(n==2) return printf("%lld ",a2),0; 28 n-=2; 29 int a[2][2]={{a2,a1},{0,0}}; 30 int b[2][2]={{p,1},{q,0}}; 31 Matrix A(a),B(b); 32 while(n){ 33 if(n&1) A=A*B; 34 B=B*B,n>>=1; 35 } 36 printf("%lld ",A.g[0][0]); 37 return 0; 38 }