Hopscotch Marathon
시간 제한1.5초메모리 제한1024 MB
각 라운드에서 번호가 c와 소인수를 공유하는 참가자의 위치에서 d를 빼며, 각 참가자가 처음 0에 도달하는 라운드 번호를 구한다.
문제
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 participants, numbered sequentially from to . It is known that the -th participant starts in the area numbered .
Hopscotch consists of rounds. During the -th round, Carlão, beloved Hopscotch organizer for longer than anyone can remember, will communicate two integers to participants: and . This is an order for all participants with identifying number such that and share a common integer factor larger than to retrogress positions in the Hopscotch court, one by one, never going back further than position . (Any participant who eventually returns to position 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 and (). The second line contains integers, namely, (). Each of the next lines contains two integers, and (, ).
출력
You must output lines. The -th line should contain a single integer, indicating the number of the round when the -th participant returns to position (or the value , if that never happens).