intmain() { int n, q; cin >> n >> q; vector<int> a(n); for (auto &nx: a) { cin >> nx; } vector<int> l(q), r(q); for (int i = 0; i < q; i++) { cin >> l[i] >> r[i]; }
uint_fast64_t seed = 202202052100238523; mt19937_64 engine(seed); vector<vector<int>> pf(MAX); for (int i = 2; i < MAX; i++) { if (!pf[i].empty()) { continue; } for (int j = i; j < MAX; j += i) { int mj = j; while (mj % i == 0) { pf[j].push_back(i); mj /= i; } } } vector<bool> res(q, true); for (int tr = 0; tr < 3; tr++) { vector<vector<uint_fast64_t>> hs(MAX, vector<uint_fast64_t>(3, 0)); for (int i = 0; i < MAX; i++) { while (hs[i][0] == 0) { hs[i][0] = engine(); } while (hs[i][1] == 0 || hs[i][0] == hs[i][1]) { hs[i][1] = engine(); } hs[i][2] = (hs[i][0] ^ hs[i][1]); } vector<int> bk(MAX, 0); vector<uint_fast64_t> rw(n + 1, 0); for (int i = 0; i < n; i++) { rw[i + 1] = rw[i]; for (auto &nx: pf[a[i]]) { rw[i + 1] ^= hs[nx][bk[nx] % 3]; bk[nx]++; } } for (int i = 0; i < q; i++) { if (rw[l[i] - 1] != rw[r[i]]) { res[i] = false; } } } for (int i = 0; i < q; i++) { if (res[i]) { cout << "Yes\n"; } else { cout << "No\n"; } } return0; }