{"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$ ($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.\n\n## Output\n\nOutput the elements of $S$ modulo $m$ in the same way as $A$ is given.\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"LGP10502","tags":["O2优化","矩阵加速"],"sample_group":[["2 2 4 \n0 1 \n1 1","1 2\n2 3"]],"created_at":"2026-03-03 11:09:25"}}