import sys import pypyjit import itertools import heapq import math from collections import deque, defaultdict, Counter import string import random input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) pypyjit.set_param('max_unroll_recursion=-1') class PrimeTable: def __init__(self, N): self.is_prime = [True] * (N + 1) self.is_prime[0] = False self.is_prime[1] = False for i in range(2, N + 1): if i * i > N: break if self.is_prime[i] is False: continue for j in range(2, N + 1): if i * j > N: break self.is_prime[i * j] = False self.primes = [n for n in range(2, N + 1) if self.is_prime[n]] def is_prime(self, n): return self.is_prime[n] class SCC: def __init__(self, N, E, I): self.N = N self.E = E self.I = I self.V = [] self.C = [] self.traverse() self.traverse2() def toDAG(self): cidx = [None] * self.N for i in range(len(self.C)): for v in self.C[i]: cidx[v] = i edge = [set() for _ in range(len(self.C))] for v in range(self.N): cv = cidx[v] for dest in self.E[v]: cdest = cidx[dest] if cv == cdest: continue edge[cv].add(cdest) edge = [list(s) for s in edge] return self.C, edge def traverse(self): flag = [False] * self.N for i in range(self.N): if flag[i] is False: self.dfs(i, flag) self.V.reverse() def traverse2(self): flag = [False] * self.N for v in self.V: if flag[v] is False: idx = len(self.C) self.C.append([]) self.dfs2(idx, v, flag) def dfs(self, v, flag): flag[v] = True for dest in self.E[v]: if flag[dest] is False: self.dfs(dest, flag) self.V.append(v) def dfs2(self, idx, v, flag): flag[v] = True self.C[idx].append(v) for dest in self.I[v]: if flag[dest] is False: self.dfs2(idx, dest, flag) primes = set(PrimeTable(10 ** 6).primes) N = int(input()) idx = defaultdict(list) E = [[] for _ in range(4 * N)] I = [[] for _ in range(4 * N)] for i in range(N): a, b = map(int, input().split()) u, v = 2 * i, 2 * i + 1 idx[a].append(u) idx[b].append(v) us, ut = 2 * u, 2 * u + 1 vs, vt = 2 * v, 2 * v + 1 E[us].append(vt) E[vt].append(us) E[ut].append(vs) E[vs].append(ut) I[us].append(vt) I[vt].append(us) I[ut].append(vs) I[vs].append(ut) for s in idx.keys(): for t in idx.keys(): n = int(str(s) + str(t)) if n in primes: for i in idx[s]: for j in idx[t]: if i == j: continue us, ut = 2 * i, 2 * i + 1 vs, vt = 2 * j, 2 * j + 1 E[us].append(vs) E[vt].append(ut) I[vs].append(us) I[ut].append(vt) scc = SCC(4 * N, E, I).C for vs in scc: vvs = [v // 2 for v in vs] if len(set(vvs)) < len(vs): print('No') exit() print('Yes')