#include #include using namespace atcoder; using namespace std; using ll = long long; using vll = vector; using vvll = vector; using vvvll = vector; #define all(A) A.begin(),A.end() #define rep(i, n) for (ll i = 0; i < (ll) (n); i++) bool chmax(ll& p, ll q) { if (p < q) { p = q; return 1; } else { return 0; } } bool chmin(ll& p, ll q) { if (p > q) { p = q; return 1; } else { return 0; } } ll PM(ll P, ll Q) { if (Q == 0)return P * 10; ll k = 1; ll V = Q; while (V > 0) { V /= 10; k *= 10; } return P * k + Q; } int main() { ll M = 2e6; vll P(M); rep(i, M)P[i] = i; P[0] = P[1] = -1; rep(i, M) { if (P[i] == i)for (ll j = i; j < M; j += i)P[j] = i; } ll N; cin >> N; two_sat sa(N); vll A(N),B(N); rep(i, N)cin >> A[i]>>B[i]; rep(i, N)rep(j, N) { //1:Ahidari ll q = PM(A[i], A[j]); if (P[q]==q) { sa.add_clause(i, 0, j, 1); } q = PM(A[i], B[j]); if (P[q] == q) { sa.add_clause(i, 0, j, 0); } q = PM(B[i], A[j]); if (P[q] == q) { sa.add_clause(i, 1, j, 1); } q = PM(B[i], B[j]); if (P[q] == q) { sa.add_clause(i, 1, j, 0); } q = PM(A[j], A[i]); if (P[q] == q) { sa.add_clause(j, 0, i, 1); } q = PM(A[j], B[i]); if (P[q] == q) { sa.add_clause(j, 0, i, 0); } q = PM(B[j], A[i]); if (P[q] == q) { sa.add_clause(j, 1, i, 1); } q = PM(B[j], B[i]); if (P[q] == q) { sa.add_clause(j, 1, i, 0); } } if (sa.satisfiable()) { cout << "Yes" << endl; } else { cout << "No" << endl; } }