#pragma GCC optimize ("O3") #ifdef LOCAL111 #define _GLIBCXX_DEBUG #else #define NDEBUG #endif #define _USE_MATH_DEFINES #include const int INF = 1e9; using namespace std; template ostream& operator<< (ostream& os, const pair& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; } #define endl '\n' #define ALL(a) (a).begin(),(a).end() #define SZ(a) int((a).size()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #ifdef LOCAL111 #define DEBUG(x) cout<<#x<<": "<<(x)< void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;} #else #define DEBUG(x) true template void dpite(T a, T b){ return; } #endif #define F first #define S second #define SNP string::npos #define WRC(hoge) cout << "Case #" << (hoge)+1 << ": " template void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;} template bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;} template bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;} template vector make_v(size_t a){return vector(a);} template auto make_v(size_t a,Ts... ts){ return vector(ts...))>(a,make_v(ts...)); } template typename enable_if::value!=0>::type fill_v(U &u,const V... v){u=U(v...);} template typename enable_if::value==0>::type fill_v(U &u,const V... v){ for(auto &e:u) fill_v(e,v...); } const array dx = {0, 1, 0, -1}; const array dy = {1, 0, -1, 0}; typedef long long int LL; typedef unsigned long long ULL; typedef pair P; void ios_init(){ cout.setf(ios::fixed); cout.precision(12); #ifdef LOCAL111 return; #endif ios::sync_with_stdio(false); cin.tie(0); } std::vector eratosthenes(int n){ std::vector res(n+1,true); res[0] = false; res[1] = false; for(long long i = 2; i*i <= n; i++){ for(long long j = 2; i*j <= n; j++){ res[i*j] = false; } } return res; } template unordered_map primeFactorizem(T x){ unordered_map res; for(T i = 2; i*i <= x; i++){ while(x%i == 0){ res[i]++; x /= i; } } if(x != 1) res[x]++; return res; } int main() { ios_init(); int n; while(cin >> n) { vector a(n); REP(i, n) cin >> a[i]; int ma = *max_element(ALL(a)); if(ma == 1) { vector zero_cnt(n+1); REP(i, n) { zero_cnt[i+1] = zero_cnt[i] + (a[i] == 0); } dpite(ALL(zero_cnt)); int q; cin >> q; REP(_, q) { LL p; int l, r; cin >> p >> l >> r; l--; DEBUG(r); DEBUG(l); DEBUG(zero_cnt[r] - zero_cnt[l]); if(p >= 2) { cout << "NO" << endl; } else { if(zero_cnt[r] - zero_cnt[l] == 0) { cout << "Yes" << endl; } else { cout << "Yes" << endl; } } } continue; } auto era = eratosthenes(ma); vector pv; REP(i, SZ(era)) if(era[i]) { DEBUG(i); pv.push_back(i); } vector> imos(SZ(pv), vector(n + 1)); vector zero_cnt(n+1); REP(i, n) { // DEBUG(a[i]); int t = a[i]; if(t == 0) { zero_cnt[i+1]++; } else { REP(j, SZ(pv)) { while(t % pv[j] == 0) { t /= pv[j]; imos[j][i + 1]++; } } assert(t == 1); } // DEBUG(t); } REP(i, n) zero_cnt[i+1] += zero_cnt[i]; REP(i, SZ(pv)) REP(j, n) { imos[i][j+1] += imos[i][j]; } int q; cin >> q; REP(_, q) { // DEBUG(_); LL p; int l, r; cin >> p >> l >> r; l--; if(zero_cnt[r] - zero_cnt[l] != 0) { cout << "Yes" << endl; continue; } vector pf(SZ(pv)); bool ans = true; REP(i, SZ(pv)) { while(p % pv[i] == 0) { p /= pv[i]; pf[i]++; } } REP(i, SZ(pv)) { if(pf[i] > imos[i][r] - imos[i][l]) { ans = false; } } if(p != 1) { ans = false; } if(ans) { cout << "Yes" << endl; } else { cout << "NO" << endl; } } } }