#include using namespace std; const int MAX = 1000000; struct strongly_connected_components{ vector> ans; vector scc; void dfs1(vector> &E, vector &t, vector &used, int v){ for (int w : E[v]){ if (!used[w]){ used[w] = true; dfs1(E, t, used, w); } } t.push_back(v); } void dfs2(vector> &E2, vector &used2, int v){ ans.back().push_back(v); for (int w : E2[v]){ if (!used2[w]){ used2[w] = true; dfs2(E2, used2, w); } } } strongly_connected_components(vector> &E){ int N = E.size(); vector> E2(N); for (int i = 0; i < N; i++){ for (int j : E[i]){ E2[j].push_back(i); } } vector t; vector used(N, false); for (int i = 0; i < N; i++){ if (!used[i]){ used[i] = true; dfs1(E, t, used, i); } } reverse(t.begin(), t.end()); vector used2(N, false); scc = vector(N); int cnt = 0; for (int i = 0; i < N; i++){ if (!used2[t[i]]){ used2[t[i]] = true; ans.push_back(vector()); dfs2(E2, used2, t[i]); for (int j : ans.back()){ scc[j] = cnt; } cnt++; } } } int operator [](int k){ return scc[k]; } int size(){ return ans.size(); } }; int con(int A, int B){ return stoi(to_string(A) + to_string(B)); } int main(){ int N; cin >> N; vector A(N), B(N); for (int i = 0; i < N; i++){ cin >> A[i] >> B[i]; } vector prime(MAX, true); for (int i = 2; i < MAX; i++){ if (prime[i]){ for (int j = i * 2; j < MAX; j += i){ prime[j] = false; } } } vector> E(N * 2); for (int i = 0; i < N; i++){ for (int j = 0; j < N; j++){ if (prime[con(A[i], A[j])]){ E[i].push_back(N + j); E[j].push_back(N + i); } if (prime[con(A[i], B[j])]){ E[i].push_back(j); E[N + j].push_back(N + i); } if (prime[con(B[i], A[j])]){ E[N + i].push_back(N + j); E[j].push_back(i); } if (prime[con(B[i], B[j])]){ E[N + i].push_back(j); E[N + j].push_back(i); } } } strongly_connected_components G(E); bool ok = true; for (int i = 0; i < N; i++){ if (G[i] == G[N + i]){ ok = false; } } if (ok){ cout << "Yes" << endl; } else { cout << "No" << endl; } }