시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 (추가 시간 없음) | 512 MB | 36 | 12 | 12 | 41.379% |
Let $a_{n}$ be a sequence defined by the recursive formula:
$$\begin{align*} a_{n+2} &= k\cdot a_{n+1} + a_{n} \\ a_{0} &= 0 \\ a_{1} &= 1 \end{align*}$$
Given a certain $k \in \{1,3,5,7\}$ and an odd prime number $p$, your task is to find the value of $a_{p} \bmod{p}$.
In the first line one integer $Z \le 10^6$ is given, denoting number of testcases described in following lines.
For each test case, first and the only input line contains two natural numbers $p$ and $k$, $p$ being an odd prime number.
For each test case you should print exactly one line containing the value of $a_{p} \bmod{p}$.
3 3 5 11 1 13 3
2 1 0