#include #define rep(i,n) for(int i = 0; i < (int)(n); i++) using namespace std; using LL = long long; using P = pair; using vv = vector>; const int INF = (int)1e9; const LL LINF = (LL)1e18; pair, vector> Eratosthenes(const int N){ vector divisor(N + 1); vector res; for(int i = 2; i <= N; i++){ if(divisor[i] == 0){ divisor[i] = 1; res.emplace_back(i); for(int j = 2 * i; j <= N; j += i) divisor[j] = i; } } return pair, vector>(res, divisor); } int main(){ int N; cin >> N; assert(1 <= N && N <= 500); vv A(N, vector(2)); rep(i,N) cin >> A[i][0] >> A[i][1]; rep(i,N){ rep(j,2){ assert(1 <= A[i][j] && A[i][j] < 1000); } } pair,vector> E = Eratosthenes(1000005); vector primes(1000010); for(auto p : E.first) primes[p]++; vector S, T; vector used(N, 1); rep(i,N){ string s1 = to_string(A[i][0]) + to_string(A[i][1]); string s2 = to_string(A[i][1]) + to_string(A[i][0]); int a = stoi(s1), b = stoi(s2); if(primes[a]){ if(primes[b]){ cout << "No" << endl; return 0; } else{ S.emplace_back(A[i][1]); T.emplace_back(A[i][0]); } } else if(primes[b]){ S.emplace_back(A[i][0]); T.emplace_back(A[i][1]); } else used[i] = 0; } rep(i,N){ if(used[i]) continue; vector res(2, true); int siz = T.size(); rep(j,siz){ rep(u,2){ string s = to_string(A[i][u]) + to_string(T[j]); int a = stoi(s); if(primes[a]) res[u] = false; } } rep(j,N){ if(i == j) continue; rep(u,2){ string s1 = to_string(A[i][u]) + to_string(A[j][0]); string s2 = to_string(A[i][u]) + to_string(A[j][1]); int a = stoi(s1), b = stoi(s2); if(primes[a] and primes[b]) res[u] = false; } } if(res[0] == false){ if(res[1] == false){ cout << "No" << endl; return 0; } else{ S.emplace_back(A[i][1]); T.emplace_back(A[i][0]); } } else{ S.emplace_back(A[i][0]); T.emplace_back(A[i][1]); } } cout << "Yes" << endl; return 0; }