It is required to solve Tr (a ^ k) % 9937. Be sure not to wait until the final result is reached. Just a moment after each processing (matrix nature: each number in the matrix is divided by/multiplied by the same integer at the same time, and the properties of the matrix remain unchanged (including the trace of the matrix, the rank of the matrix, and the simplest tiered determining factor of the matrix, etc.); otherwise, the number overflows. [Cpp] # include <iostream> # include <cmath> # include <cstring> using namespace std; class Mat {public: int mat [15] [15];}; int n; // dimension, that is, the number of rows in matrix A int MOD = 9973; // The number Mat E after the remainder is required for many questions; void initE () {for (int I = 0; I <15; I ++) E. mat [I] [I] = 1;} Mat operator * (Mat a, Mat B) {int I, j, k; Mat c; for (I = 0; I <n; I ++) {for (j = 0; j <n; j ++) {c. mat [I] [j] = 0; for (k = 0; k <n; k ++) {c. mat [I] [j] + = (. mat [I] [k] * B. mat [k] [j]);} c. mat [I] [j] % = MOD;} return c;} Mat operator + (Mat a, Mat B) {Mat c; int I, j; for (I = 0; I <n; I ++) {for (j = 0; j <n; j ++) c. mat [I] [j] =. mat [I] [j] + B. mat [I] [j]; c. mat [I] [j] % = 9973;} return c;} Mat operator ^ (Mat a, int x) {Mat p = E, q =; while (x> = 1) {if (x % 2 = 1) p = p * q; x/= 2; q = q * q;} return p ;} mat solve (Mat a, int p) {if (p = 1) return a; else if (p & 1) return (a ^ p) + solve (, p-1); else return (a ^ (p> 1) + E) * solve (a, p> 1);} int main () {int testcase; cin> testcase; Mat at, bt; int res; int kp; while (testcase --) {res = 0; initE (); memset (. mat, 0, sizeof (. mat); memset (bt. mat, 0, sizeof (bt. mat); cin> n> kp; for (int I = 0; I <n; I ++) {www.2cto.com for (int j = 0; j <n; j ++) {cin>. mat [I] [j] ;}} bt = at ^ kp; for (int I = 0; I <n; I ++) {res + = bt. mat [I] [I];} cout <res % 9973 <endl;} return 0 ;}