Master Zhu and Root

아직 제출이 없습니다시간 제한3초메모리 제한512 MB

문제

Master Zhu has a number nn. He asks you qq queries, the ii-th query is a pair of integers (x_i,y_i)(x\_i, y\_i). For ii-th query, Master Zhu would like you to find the smallest non-negative integer k_ik\_i such that, for some pp which is a prime divisor of nn, the equivalence x_ik_iy_ix\_i^{k\_i} \equiv y\_i modulo pp holds, or to determine that no such k_ik\_i exists.

In this problem, we consider that 00=10^0 = 1.

입력

The first line of input contains two integers nn and qq (1n1081 \le n \le 10^8, 1q1051 \le q \le 10^5). Each of the next qq lines contains two integers x_ix\_i and y_iy\_i (0x_i,y_i1090 \le x\_i, y\_i \le 10^9).

출력

For each query, print the answer on a separate line. If you found k_ik\_i, print it, otherwise print the number 1-1.