Số học 2

View as PDF

Submit solution

Points: 1.03 (partial)
Time limit: 1.0s
Memory limit: 512M
Input: stdin
Output: stdout

Problem source:
Base on a problem of Michael Medvedev
Problem type
Allowed languages
C, C++, Go, Java, Kotlin, Pascal, PyPy, Python, Rust, Scratch

Tìm tất cả số các nguyên ~x~ thoả mãn ~x^2~ ~\equiv~ ~a~ ~(mod~ ~n)~. Trong đó ~n~ là số nguyên tố và ước chung lớn nhất của ~a~ và ~n~ bằng ~1~, ~0 \leq x \leq n - 1~ .

Input

Dòng ~1~: số nguyên ~K~ là số bộ test ~\left( 1 \leq K \leq 120000 \right)~.

~K~ dòng tiếp theo: mỗi dòng gồm ~2~ số nguyên ~a , n~ ~\left( 1 \leq a, n \leq 1000000 \right)~.

Output

Với mỗi test ghi ra tất cả các số nguyên ~x~ thoả mãn theo thứ tự tăng dần trên 1 dòng . Nếu không có số nguyên ~x~ nào thoả mãn thì ghi ra "Khong co".

Sample Input

5
4 17
3 7
2 7
14 31
10007 20011

Sample Output

2 15
Khong co
3 4
13 18
5382 14629

Comments

Please read the guidelines before commenting.


There are no comments at the moment.