#P5605. 小 A 与两位神仙

小 A 与两位神仙

Description

One day, Little A was walking home after school when he suddenly met two immortal dream-makers, Zaomengzhe and Jeremy. As soon as they saw Little A, they said they wanted to play a game with him. Little A was covered in golden light and, for some reason, agreed to their request.

The rules of the game are as follows: the two immortals first choose a positive integer mm, and guarantee that mm is a positive integer power of an odd prime pp. Then they play nn rounds. In each round, Zaomengzhe chooses a positive integer xx, and Jeremy chooses a positive integer yy, with (x,m)=1(x, m) = 1 and (y,m)=1(y, m) = 1, meaning xx is coprime to mm and yy is coprime to mm. Then they ask Little A whether there exists a non-negative integer aa such that xay(modm)x^a \equiv y \pmod{m}.

The immortals say that only if Little A answers correctly in every round can he return to normal life. With no other choice, he asks you, the smart one, for help.

Input Format

The first line contains two positive integers m,nm, n.

The next nn lines each contain two positive integers x,yx, y.

Output Format

Output a total of nn lines, each corresponding to Little A's answer for one round.

If it exists, output Yes; otherwise, output No.

9 3
1 4
2 1
7 4
No
Yes
Yes
29788562298698657 10
4623623705787050 4128735493476588
29371111781967946 19402395181570597
23313713550468151 18155134012955455
654639695903289 323875358727922
15727861955653242 26658913688488667
10815360622718474 4625834559167483
10836636083182170 10347869939717751
8972909638986721 1887397472131862
23442032136521081 29735793306181382
325363900801763 6960017105353559

Yes
No
No
Yes
Yes
Yes
No
Yes
Yes
No

Hint

Sample Explanation

1a1≢4(mod9)1^a \equiv 1 \not \equiv 4 \pmod {9}.

26641(mod9)2^6 \equiv 64 \equiv 1 \pmod {9}.

72494(mod9)7^2 \equiv 49 \equiv 4 \pmod {9}.

Constraints

This problem has 77 subtasks. You must pass all test points within a subtask to obtain the score for that subtask.

For all testdata, 1n2×1041\le n\le 2\times 10^4, 3m10183\le m \le 10^{18}, 1x,y<m1 \le x, y < m.

# Score nn mm Special Property 1 Time Limit
1 3 5\le 5 106\le 10^6 × 1s
2 37 109\le 10^9
3 22 =1= 1 1018\le 10^{18}
4 13 100\le 100
5 10 ×
6 5 2000\le 2000
7 10 2×104\le 2\times 10^4 3s

Special Property 1: Let m=pam = p^{a}. Then pp is a prime chosen uniformly at random from [3,1018][3, 10^{18}].

Hint

You may use __int128.

Translated by ChatGPT 5