#abc210f. F - Coprime Solitaire

F - Coprime Solitaire

Score : 600600 points

问题描述

我们有 NN 张卡片排成一行放在桌子上。对于每个 i=1,2,,Ni = 1, 2, \ldots, N,第 ii 张卡片正面写有一个整数 AiA_i,背面写有一个整数 BiB_i。最初,每张卡片都被面朝上放置。

高桥将会选择任意数量他喜欢的卡片(可能为零)并将它们翻转。然后,如果满足以下条件,他将会很开心:

  • 对于所有整数对 (i,j)(i, j),满足 1i<jN1 \leq i < j \leq N,在第 ii 张和第 jj 张卡片上可见的整数是互质的。

确定是否有可能让高桥变得开心。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have NN cards arranged in a row on a table. For each i=1,2,,Ni = 1, 2, \ldots, N, the ii-th card has an integer AiA_i written on the front and an integer BiB_i written on the back. Initially, every card is placed face up.

Takahashi will choose any number of cards he likes (possibly zero) and flip them. Then, he will be happy if the following condition is satisfied:

  • for every pair of integers (i,j)(i, j) such that 1i<jN1 \leq i \lt j \leq N, the integers visible on the ii-th and jj-th cards are coprime.

Determine whether it is possible for Takahashi to be happy.

Constraints

  • 1N3×1041 \leq N \leq 3 \times 10^4
  • 1Ai,Bi2×1061 \leq A_i, B_i \leq 2 \times 10^6
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 B1B_1

A2A_2 B2B_2

\vdots

ANA_N BNB_N

Output

If it is possible for Takahashi to be happy, print Yes; otherwise, print No.

Sample Input 1

3
2 5
10 9
4 8

Sample Output 1

Yes

Initially, we see integers 22, 1010, and 44. If we flip the first and second cards, we will see 55, 99, and 44, which will make Takahashi happy. Thus, we should print Yes.

Sample Input 2

2
10 100
1000 10000

Sample Output 2

No

There is no way to flip cards to make Takahashi happy, so we should print No.

update @ 2024/3/10 09:25:22