import sys input = sys.stdin.readline sys.setrecursionlimit(1010) def era(n): is_prime = [True]*(n+1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5)+1): if not is_prime[i]: continue for j in range(2*i, n+1, i): is_prime[j] = False return is_prime class Scc: def __init__(self, N, G): self.N = N self.G = G self.RG = [[] for _ in range(N)] for v in range(N): for nv in G[v]: self.RG[nv].append(v) def decomp(self): order = [] visited = [False]*self.N def dfs(v): visited[v] = True for nv in self.G[v]: if not visited[nv]: dfs(nv) order.append(v) for v in range(self.N): if not visited[v]: dfs(v) visited = [False]*self.N comp = [-1]*self.N label = 0 def rdfs(v, label): comp[v] = label visited[v] = True for nv in self.RG[v]: if not visited[nv]: rdfs(nv, label) for v in reversed(order): if not visited[v]: rdfs(v, label) label += 1 return label, comp def is_p(p, q): return is_prime[p*pow(10, len(str(q)))+q] N = int(input()) AB = [tuple(map(int, input().split())) for _ in range(N)] is_prime = era(10**6+10) G = [[] for _ in range(2*N)] for i in range(N): Ai, Bi = AB[i] for j in range(i, N): Aj, Bj = AB[j] if is_p(Ai, Bj) or is_p(Aj, Bi): G[2*i+1].append(2*j) G[2*j+1].append(2*i) if is_p(Bi, Bj) or is_p(Aj, Ai): G[2*i].append(2*j) G[2*j+1].append(2*i+1) if is_p(Ai, Aj) or is_p(Bj, Bi): G[2*i+1].append(2*j+1) G[2*j].append(2*i) if is_p(Bi, Aj) or is_p(Bj, Ai): G[2*i].append(2*j+1) G[2*j].append(2*i+1) scc = Scc(2*N, G) _, comp = scc.decomp() for i in range(N): if comp[2*i]==comp[2*i+1]: exit(print('No')) print('Yes')