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 UnionFind: def __init__(self, N): self.N = N self.par = [-1] * N def find(self, x): if self.par[x] < 0: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return False if x > y: x, y = y, x self.par[x] += self.par[y] self.par[y] = x return True def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.par[self.find(x)] def roots(self): return [i for i in range(self.N) if self.par[i] < 0] def members(self, x): p = self.find(x) return [i for i in range(self.N) if self.find(i) == p] N = int(input()) nums = [] for i in range(N): a, b = map(int, input().split()) nums.append(a) nums.append(b) primes = set(PrimeTable(10 ** 6).primes) uf = UnionFind(4 * N) for i in range(N): u, v = 2 * i, 2 * i + 1 ua, ub = 2 * u, 2 * u + 1 va, vb = 2 * v, 2 * v + 1 uf.unite(ua, vb) uf.unite(ub, va) for u in range(2 * N): for v in range(u + 1, 2 * N): s, t = nums[u], nums[v] n = int(str(s) + str(t)) if n in primes: ua, ub = 2 * u, 2 * u + 1 va, vb = 2 * v, 2 * v + 1 uf.unite(ua, vb) uf.unite(ub, va) for i in range(2 * N): va, vb = 2 * i, 2 * i + 1 if uf.same(va, vb): print('No') exit() print('Yes')