Hopscotch Marathon

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

문제

October 8th, 2022. This is the date of the most awaited event of the year by computer science students across the country. No, we are not talking about ICPC.

We are talking, of course, about Hopscotch! For those unfamiliar, Hopscotch is an annual competition traditionally held as an ICPC side event. Live streamed to spectators from all continents, and to practitioners of the most esoteric programming languages, this exotic variant of the popular children’s game takes place in an infinite, spiral-shaped court, subdivided into sequentially numbered areas starting at zero, as depicted below.

This year, Hopscotch has attracted a record number of NN participants, numbered sequentially from 11 to NN. It is known that the ii-th participant starts in the area numbered A_iA\_i.

Hopscotch consists of QQ rounds. During the qq-th round, Carlão, beloved Hopscotch organizer for longer than anyone can remember, will communicate two integers to participants: c_qc\_q and d_qd\_q. This is an order for all participants with identifying number ii such that ii and c_qc\_q share a common integer factor larger than 11 to retrogress d_qd\_q positions in the Hopscotch court, one by one, never going back further than position 00. (Any participant who eventually returns to position 00 should remain there indefinitely, ignoring any further retrogress commands, so as not to leave the court.)

Under the assumption that the participants have executed the instructions perfectly (they would never want to disappoint Carlão), your task is to determine, for each participant, the number of the round in which he or she returns to position 0 (or otherwise indicate that this never happens).

입력

The first line contains the integers NN and QQ (1N,Q1051 ≤ N, Q ≤ 10^5). The second line contains NN integers, namely, A_1,A_2,,A_NA\_1, A\_2, \cdots , A\_N (1A_i1091 ≤ A\_i ≤ 10^9). Each of the next QQ lines contains two integers, c_qc\_q and d_qd\_q (1c_q1051 ≤ c\_q ≤ 10^5, 1d_q1091 ≤ d\_q ≤ 10^9).

출력

You must output NN lines. The ii-th line should contain a single integer, indicating the number of the round when the ii-th participant returns to position 00 (or the value 1-1, if that never happens).