#include #include #include #include #include using namespace std; using namespace atcoder; using ll = long long; using ull = unsigned long long; static inline ll fast_read() { int c = getchar_unlocked(); while (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\v' || c == '\f') { c = getchar_unlocked(); } bool negative = false; if (c == '-' || c == '+') { negative = c == '-'; c = getchar_unlocked(); } ull value = 0; while ('0' <= c && c <= '9') { value = value * 10 + (ull)(c - '0'); c = getchar_unlocked(); } if (c != EOF) { ungetc(c, stdin); } return negative ? -(ll)value : (ll)value; } static bitset<1000000> pt; static bool hate(ll a, ll b) { ll x = stoll(to_string(a) + to_string(b)); return pt[x]; } int main() { const int m = 1000000; pt.set(); pt[0] = pt[1] = false; for (ll p = 2; p * p < m; p++) { if (pt[p]) { for (ll q = p * p; q < m; q += p) { pt[q] = false; } } } int n; n = (int)fast_read(); vector as(n), bs(n); for (int i = 0; i < n; i++) { as[i] = fast_read(); bs[i] = fast_read(); } two_sat ts(n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (!hate(as[i], bs[j])) { continue; } if (i == j) { ts.add_clause(i, false, i, false); continue; } ts.add_clause(i, false, j, false); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (!hate(bs[j], as[i])) { continue; } if (i == j) { ts.add_clause(i, true, i, true); continue; } ts.add_clause(i, true, j, true); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j || !hate(as[i], as[j])) { continue; } ts.add_clause(i, false, j, true); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j || !hate(bs[i], bs[j])) { continue; } ts.add_clause(i, true, j, false); } } puts(ts.satisfiable() ? "Yes" : "No"); }