| ps | |
|---|---|
| 링크 | acmicpc.net/… |
| 출처 | BOJ |
| 문제 번호 | 32594 |
| 문제명 | Kangaroo Race |
| 레벨 | 골드 3 |
| 분류 |
수학 |
| 시간복잡도 | O(T*logn) |
| 인풋사이즈 | T<=10^5, n<=10^18 |
| 사용한 언어 | Python 3.11 |
| 제출기록 | 31120KB / 1264ms |
| 최고기록 | 1264ms |
| 해결날짜 | 2024/11/01 |
"""Solution code for "BOJ 32594. Kangaroo Race".
- Problem link: https://www.acmicpc.net/problem/32594
- Solution link: http://www.teferi.net/ps/problems/boj/32594
Tags: [math]
"""
import sys
def main():
k = int(sys.stdin.readline())
for _ in range(k):
n, x = [int(x) for x in sys.stdin.readline().split()]
if x == 1:
print('0')
continue
answer = next(
(i for i in range(1, n.bit_length() + 1) if (x := x * x % n) == 1),
None,
)
print('impossible' if answer is None else answer)
if __name__ == '__main__':
main()