#include #define LOCAL using std::to_string; auto to_string(std::string s) -> std::string { return '"' + s + '"'; } auto to_string(char c) -> std::string { return "'" + std::string{c} + "'"; } auto to_string(const char* s) -> std::string { return to_string((std::string) s); } auto to_string(bool b) -> std::string { return (b ? "true" : "false"); } template auto to_string(std::pair p) -> std::string { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template auto to_string(std::bitset bs) -> std::string { std::string res{}; for (size_t i = 0; i < N; i++) res.insert(res.begin(), bs.test(i) ? '1' : '0'); return res; } template auto to_string(T v) -> std::string { bool flg = false; std::string res = "{"; for (auto const&x : v) { if (flg) res += ", "; else flg = true; res += to_string(x); } res += "}"; return res; } void debug_out() { std::cerr << std::endl; } template void debug_out(Head H, Tail... T) { std::cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif template class sieve_of_eratosthenes { std::bitset is_prime_; public: constexpr sieve_of_eratosthenes(){ is_prime_ = ~is_prime_; is_prime_.reset(0), is_prime_.reset(1); for (size_t p = 2; p < N; p++) { if (!is_prime_.test(p)) continue; for (size_t j = 2; j * p < N; j++) { is_prime_.reset(p * j); } } } // Return the bitset testing if a number is prime. constexpr const auto& is_prime() const {return is_prime_;} // Returns the vector of prime numbers. template auto primes() const { std::vector primes{}; for (size_t i = 0; i < N; i++) { if (is_prime_.test(i)) primes.push_back(i); } return primes; } }; template auto make_vector(size_t sz, T t) { return std::vector(sz, t); } template = nullptr> auto make_higher_vector(size_t sz, U u) { return make_vector(sz, T(u)); } template = nullptr> auto make_higher_vector(size_t sz) { return std::vector(sz); } template = nullptr> auto make_higher_vector(size_t a, Args... args) { return make_vector(a, make_higher_vector(args...)); } template auto& at(T& t, Size_t i) { return t.at(i); } template auto& at(T& t, Size_t i, Args... args) { return at(t.at(i), args...); } int main() { std::cin.tie(0); std::cin.sync_with_stdio(false); constexpr int pmax = 200000; auto primes = sieve_of_eratosthenes{}.primes(); int psize = primes.size(); auto ind = [&] (int x) { assert(2 <= x && x <= pmax); auto lb = std::lower_bound(primes.begin(), primes.end(), x); assert(x == *lb); return lb - primes.begin(); }; auto factorize = [&] (int x) { std::vector ret; for (auto p : primes) { for (; x % p == 0; x /= p) { ret.push_back(ind(p)); } if (x == 1) break; } if (x != 1) return std::vector{}; return ret; }; int n; std::cin >> n; auto a = [&] { std::vector a(n); for (auto&x : a) std::cin >> x; a.insert(a.begin(), -1); return a; }(); int q; std::cin >> q; auto cum = [&] { auto cum = std::vector(psize, std::vector(n + 1, 0)); for (int i = 1; i <= n; i++) { auto crr = a.at(i); auto factors = factorize(crr); for (auto x : factors) { at(cum, x, i)++; } } for (auto& v : cum) { auto new_v = std::vector(n + 1, 0); std::partial_sum(v.begin(), v.end(), new_v.begin()); v = std::move(new_v); } return cum; }(); auto range_sum = [&] (int i, int l, int r) { return at(cum, i, r) - at(cum, i, l); }; while (q--) { int p, l, r; std::cin >> p >> l >> r; l--; bool ans = true; auto factors = factorize(p); if (p != 1 && factors.size() == 0) ans = false; int mlt = 0, prv = -1; for (auto x : factors) { if (x != prv) { if (prv != -1 && range_sum(x, l, r) < mlt) ans = false; mlt = 0; } mlt++; prv = x; } if (mlt > 0) { if (range_sum(prv, l, r) < mlt) ans = false; } std::cout << (ans ? "Yes" : "No") << std::endl; } return 0; }