Logo
(追記) (追記ここまで)

23466번 - What a sequence! 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 512 MB38141443.750%

문제

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}$.

제한

  • $k \in \{1,3,5,7\}$
  • The total length of the numbers $p$ in the all testcases doesn't exceed 10ドル^{6}$.

예제 입력 1

3
3 5
11 1
13 3

예제 출력 1

2
1
0

힌트

출처

Contest > Open Cup > 2019/2020 Season > Stage 14: Grand Prix of Wroclaw C번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /