#P1707. 刷题比赛

    ID: 671 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>递推倍增矩阵运算洛谷原创矩阵乘法线性递推,递推式

刷题比赛

Description

Luogu OJ is certainly a good place, and nodgd wants to share it with friends. So he invited his friends Ciocio and Nicole to practice problems together. Since they love contests, they naturally would not miss such an opportunity for a problem-solving contest!

On day 11, nodgd, Ciocio, Nicole each solved 11 problem.

On day 22, nodgd, Ciocio, Nicole each solved 33 problems.

They all have strict rules for solving problems and will strictly follow the rules to solve a certain number of problems each day.

  1. The number of problems nodgd solves on day k+2k+2:
ak+2=pak+1+qak+bk+1+ck+1+rk2+tk+1a_{k+2}=pa_{k+1}+qa_k+b_{k+1}+c_{k+1}+rk^2+tk+1
  1. The number of problems Ciocio solves on day k+2k+2:
bk+2=ubk+1+vbk+ak+1+ck+1+wkb_{k+2}=ub_{k+1}+vb_k+a_{k+1}+c_{k+1}+w^k
  1. The number of problems Nicole solves on day k+2k+2:
$$c_{k+2} = xc_{k+1}+yc_k + a_{k+1} + b_{k+1} + z^k+k+2$$

(All letters p,q,r,t,u,v,w,x,y,zp, q, r, t, u, v, w, x, y, z are given constants and are guaranteed to be positive integers.)

Then they started a long problem-solving contest, lasting for nn days.

However, time is precious, and nodgd wants to quickly know how many problems each person solves on day nn.
But nodgd still has a lot of math contest problems, physics contest problems, English contest problems, art contest problems, PE contest problems… to do, so please help him calculate.

Because the results can be large, output the values mod m\bmod \space m.

Input Format

The first line contains two positive integers n,mn, m.

The second line contains four positive integers p,q,r,tp, q, r, t.

The third line contains three positive integers u,v,wu, v, w.

The fourth line contains three positive integers x,y,zx, y, z.

Output Format

Output three lines, each containing a name + a space + an integer.
In order: nodgd, Ciocio, Nicole, and their number of problems solved on day nn mod m\bmod \space m.

4 10007
2 1 1 1
2 2 3
1 1 2
nodgd 74
Ciocio 80
Nicole 59

Hint

For 100%100\% of the testdata, 4n10164 \le n \le 10^{16}, 2m10162 \le m \le 10^{16}, 1p,q,r,t,u,v,w,x,y,z1001 \le p, q, r, t, u, v, w, x, y, z \le 100.

Translated by ChatGPT 5