PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000343. Lật thẻ để các số đôi một nguyên tố cùng nhau (Coprime Solitaire)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Lật thẻ để các số đôi một nguyên tố cùng nhau (Coprime Solitaire)
Coprime Solitaire
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are cards. Card has on its front and on its back; initially every card is face up.
You may flip any subset of the cards, including none. Each card then displays exactly one of its two values.
Determine whether the displayed numbers can be made pairwise coprime: for every , the chosen values must satisfy .
Input
The first line contains , followed by lines each with .
Output
Print Yes if a valid selection exists; otherwise print No.
Subtasks
- Subtask 1 (20 points): , .
- Subtask 2 (30 points): , .
- Subtask 3 (50 points): , .
Examples
Example 1
Input
3
2 5
10 9
4 8
Output
Yes
Explanation
Flip cards 1 and 2, leaving card 3 unchanged. The displayed numbers have pairwise GCD equal to 1.
Example 2
Input
2
10 100
1000 10000
Output
No
Explanation
Every face value is divisible by 10, so any two chosen values have GCD at least 10.