Combination Lock
시간 제한2초메모리 제한1024 MB
각 구간에서 수를 하나씩 골라 모든 쌍이 서로소가 되도록 하거나 불가능함을 판정한다.
문제
Your house is protected by a combination lock containing rotating discs, numbered from to . On a typical combination lock, each rotating disc has symbols, represented by integers between to , inclusive. Since you are a mathematician, your combination lock is not typical. Instead, each rotating disc on your combination lock may have a different number of symbols. In particular, rotating disc has symbols, represented by integers between to , inclusive.
The combination lock is unlocked when each rotating disc displays one integer, and any pair of two integers displayed by the rotating disc are coprime. Two integers are coprime if they do not have any common positive factors other than .
You want to unlock the combination lock, so you want to determine what integer to be displayed on each combination lock to satisfy the requirement above. It is possible that your combination lock was sabotaged when you were gone so it might be impossible to unlock your combination lock.
입력
The first line of input contains one integer (). Each of the next lines contains two integers. The -th line contains and ().
출력
Output one line containing integers, where the -th integer represents the integer to be displayed by rotating disc to unlock the combination lock. If there are multiple solutions, you can output any of them. If there is no solution, output just the integer -1.