若能根据关系 推出转移矩阵 就是简单题
然而这需要多做题的经验
ll Ax, Ay, A0, B0 ,Bx,By; struct Mat { ll m[5][5]; }; Mat E; Mat P; void init() { for (int i = 0; i < 5; i++) E.m[i][i] = 1; P.m[0][0] = 1ll; Ax %= MOD; Bx %= MOD; A0 %= MOD; B0 %= MOD; P.m[0][1] = (Ax * Bx)%MOD; P.m[0][2] = (By * Ax)%MOD; P.m[0][3] = (Ay * Bx)%MOD; P.m[0][4] = (Ay * By)%MOD; P.m[1][1] = (Ax * Bx)%MOD; P.m[1][2] = (By * Ax)%MOD; P.m[1][3] = (Ay * Bx)%MOD; P.m[1][4] = (Ay * By)%MOD; P.m[2][2] = Ax; P.m[2][4] = Ay; P.m[3][3] = Bx; P.m[3][4] = By; P.m[4][4] = 1ll; } Mat mul(const Mat& a, const Mat& b) { Mat c; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { c.m[i][j] = 0; for (int k = 0; k < 5; k++) c.m[i][j] = (c.m[i][j] + (a.m[i][k] * b.m[k][j])%MOD)%MOD; } } return c; } Mat quickPower(Mat a, ll b) { Mat ans = E; Mat base = a; while (b) { if (b & 1) ans = mul(ans, base); base = mul(base, base); b >>= 1; } return ans; } int main() { ll n; while (~scanf("%lld%lld%lld%lld%lld%lld%lld", &n, &A0, &Ax, &Ay, &B0, &Bx, &By)) { init(); ll res = (A0 * B0) % MOD; if (n == 0) { puts("0"); continue; } if (n == 1) { printf("%lld ", res); continue; } Mat ans = quickPower(P, n - 1); res = (((ans.m[0][0] * res) % MOD + (ans.m[0][1] * res) % MOD)%MOD + (((A0 * ans.m[0][2]) % MOD + B0 * ans.m[0][3] % MOD)%MOD + 1ll * ans.m[0][4] % MOD)%MOD)%MOD; printf("%lld ", res); } }