Matrix Power Series

Luogu
IDLGP10502
Time1000ms
Memory512MB
DifficultyP5
O2优化矩阵加速
Givena $n×n$ matrix $A$ and apositive integer $k$,find the sum $S=A+A^2 +A^3 +...+A^k$. ## Input The input contains exactly one test case. The first line of input contains three positive integers $n$ ($n \le 30$), $k$ ($k \le 10^9$) and $m$ ($m < 10^4$). Then follow n lines each containing $n$ non negative integers below 32,768, giving $A$’s elements in row-major order. ## Output Output the elements of $S$ modulo $m$ in the same way as $A$ is given. [samples]
Samples
Input #1
2 2 4 
0 1 
1 1
Output #1
1 2
2 3
API Response (JSON)
{
  "problem": {
    "name": "Matrix Power Series",
    "description": {
      "content": "Givena $n×n$ matrix $A$ and apositive integer $k$,find the sum $S=A+A^2 +A^3 +...+A^k$.",
      "description_type": "Markdown"
    },
    "platform": "Luogu",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 524288
    },
    "difficulty": {
      "LuoguStyle": "P5"
    },
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "LGP10502"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Givena $n×n$ matrix $A$ and apositive integer $k$,find the sum $S=A+A^2 +A^3 +...+A^k$.\n\n## Input\n\nThe input contains exactly one test case. The first line of input contains three positive integers $n...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments