import sys,random,bisect from collections import deque,defaultdict import heapq from itertools import permutations from math import gcd input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) class scc_graph: def __init__(self, N): self.N = N self.edges = [] def csr(self): self.start = [0]*(self.N+1) self.elist = [0]*len(self.edges) for e in self.edges: self.start[e[0]+1] += 1 for i in range(1, self.N+1): self.start[i] += self.start[i-1] counter = self.start[:] for e in self.edges: self.elist[counter[e[0]]] = e[1] counter[e[0]] += 1 def add_edge(self, v, w): self.edges.append((v, w)) def scc_ids(self): self.csr() N = self.N now_ord = group_num = 0 visited = [] low = [0]*N order = [-1]*N ids = [0]*N parent = [-1]*N stack = [] for i in range(N): if order[i] == -1: stack.append(i) stack.append(i) while stack: v = stack.pop() if order[v] == -1: low[v] = order[v] = now_ord now_ord += 1 visited.append(v) for i in range(self.start[v], self.start[v+1]): to = self.elist[i] if order[to] == -1: stack.append(to) stack.append(to) parent[to] = v else: low[v] = min(low[v], order[to]) else: if low[v] == order[v]: while True: u = visited.pop() order[u] = N ids[u] = group_num if u == v: break group_num += 1 if parent[v] != -1: low[parent[v]] = min(low[parent[v]], low[v]) for i, x in enumerate(ids): ids[i] = group_num-1-x return group_num, ids def scc(self): group_num, ids = self.scc_ids() groups = [[] for _ in range(group_num)] for i, x in enumerate(ids): groups[x].append(i) return groups class two_sat: def __init__(self,N): self.N = N self.answer = [-1]*N self.scc = scc_graph(2*N) def add_clause(self,i,f,j,g): self.scc.add_edge(2*i+(f==0),2*j+(g==1)) self.scc.add_edge(2*j+(g==0),2*i+(f==1)) def satisfiable(self): _,ids = self.scc.scc_ids() for i in range(N): if ids[2*i] == ids[2*i+1]: return False self.answer[i] = ids[2*i] < ids[2*i+1] return True M = 10**6 prime = [True] * (M+1) prime[1] = False for p in range(2,M+1): if not prime[p]: continue for n in range(2*p,M+1,p): prime[p] = False def check(x,y): n = int(str(x) + str(y)) return prime[n] N = int(input()) AB = [tuple(mi()) for i in range(N)] G = two_sat(N) for i in range(N): a,b = AB[i] for j in range(N): c,d = AB[j] if check(a,d) or check(c,b): G.add_clause(i,1,j,1) if check(a,c) or check(d,b): G.add_clause(i,1,j,0) if check(b,d) or check(c,a): G.add_clause(i,0,j,1) if check(b,c) or check(d,a): G.add_clause(i,0,j,0) if G.satisfiable(): print("Yes") else: print("No")