問題一覧 > 通常問題

No.950 Matrix Power

レベル : / AI推定難易度 : 2900 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 11
作問者 : chocorusk / テスター : tempura_pp
お気に入りにしたユーザー ProblemId : 3672 / 自分の提出
問題文最終更新日: 2019-12-11 15:15:17
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
Advent Calendar Contest 2019 (順位表) の他の問題:

Problem Statement

You are given $2\times 2$ matrices $A$, $B$ with integer entries and a prime $p$. Determine whether there exists a positive integer $n$ satisfying $A^n\equiv B \pmod p$, and if one exists, find the minimum such value.

Input

$p$
$A_{11}\ A_{12}$
$A_{21}\ A_{22}$
$B_{11}\ B_{12}$
$B_{21}\ B_{22}$

  • $2\leq p\leq 2\times 10^9$
  • $p$ is a prime.
  • $0\leq A_{ij}, B_{ij}\leq p-1$
  • All inputs are integers.

Output

If no positive integer $n$ satisfying the condition exists, print $-1$. Otherwise, print the minimum possible value of $n$.

Sample

Sample 1
Input
5
4 4
4 1
1 1
1 4
Output
5

$\begin{pmatrix}4&4\\4&1\end{pmatrix}^5=\begin{pmatrix}9616&6676\\6676&4609\end{pmatrix}\equiv \begin{pmatrix}1&1\\1&4\end{pmatrix}\pmod 5$.

Sample 2
Input
7
3 2
4 5
0 6
1 2
Output
-1

Sample 3
Input
2
0 0
0 0
1 0
0 1
Output
-1

Sample 4
Input
1117117717
498588348 761212524
862899722 426122834
245821018 655774117
149233593 294448965
Output
334

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。