#pragma GCC optimize("O2") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define whlie while #define retunr return #define reutrn return #define reutnr return #define mp make_pair #define pb push_back #define eb emplace_back #define fi first #define se second #define inf 1001001001 #define MOD 998244353 #define infLL (1LL << 61) #define FOR(i,a,b) for(int (i)=(int)(a); (i)<(int)(b); (i)++) // [a,b) #define rep(i,N) FOR((i), 0, (int)(N)) // [0,N) #define FORR(i,a,b) for(int (i)=(int)(b) - 1; (i)>=(int)(a); (i)--) #define repr(i,N) FORR((i), 0, (int)(N)) #define each(x,v) for(auto &x : v) #define all(v) (v).begin(),(v).end() #define sz(v) ((int)(v).size()) #define vrep(v,it) for(auto it=v.begin();it!=v.end();it++) #define vrepr(v,it) for(auto it=v.rbegin();it!=v.rend();it++) #define ini(...) int __VA_ARGS__; in(__VA_ARGS__) #define inl(...) ll __VA_ARGS__; in(__VA_ARGS__) #define inc(...) char __VA_ARGS__; in(__VA_ARGS__) #define ins(...) string __VA_ARGS__; in(__VA_ARGS__) #define ind(...) double __VA_ARGS__; in(__VA_ARGS__) #define inpii(...) pii __VA_ARGS__; in(__VA_ARGS__) //#define rand mtrand //#define randinit random_device seed_gen; mt19937_64 mtrand(seed_gen()) #ifdef LOCAL #define trc(...) do { cout << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0) #define stopif(val) assert( !(val) ) #define trcv(v,...) do { cout << #v << " = "; vector_debug(v , ##__VA_ARGS__);cout << endl;} while(0) #else #define trc(...) #define stopif(...) #define trcv(...) #endif using namespace std; using ll = long long; using pii = pair; using pll = pair; using vi = vector; using vl = vector; using vs = vector; using vpii = vector; using vvi = vector< vector >; struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15);} } iosetupnya; /* int gcd(int a, int b){if(a>b) swap(a,b); return a==0 ? b : gcd(b%a,a);} ll gcd(ll a, ll b){if(a>b) swap(a,b); return a==0 ? b : gcd(b%a,a);} ll lcm(int a, int b){return (1LL * a / gcd(a,b)) * b;} ll lcm(ll a, ll b){return (a / gcd(a,b)) * b;} */ inline ll pow(int a, int b){ll ans = 1; rep(i,b) ans *= a; return ans;} inline ll pow(ll a, ll b){ll ans = 1; rep(i,b) ans*= a; return ans;} inline ll pow(int a, ll b){ll ans = 1; rep(i,b) ans *= a; return ans;} inline ll pow(ll a, int b){ll ans = 1; rep(i,b) ans*= a; return ans;} template inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; } template inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; } template inline void _cin(C &c){cin >> c;} template inline void _cin(pair &p){cin >> p.fi; cin >> p.se;} template inline void _cout(const C &c){cout << c;} template inline void _cout(const pair &p){cout << p.fi << ' ' << p.se;} void in(){} template void in(T &t,U &...u){ _cin(t); in(u...);} void out(){cout << "\n";} template void out(const T &t,U ...u){ _cout(t); if(sizeof...(u)) cout << ' '; out(u...);} template inline void in(vector &v,int N=-1){if(sz(v) != 0){int M=(N == -1) ? sz(v) : N; rep(i,M) _cin(v[i]);}else{C c;rep(i,N) v.pb((_cin(c),c));}} template inline void in(C v[],int N){rep(i,N) _cin(v[i]);} template inline void out(const vector &v,int N=-1){int M=(N == -1) ? sz(v) : N; rep(i,M) {cout<<( (i)?" ":"" ); _cout(v[i]);} cout<<"\n";} template inline void out(C v[],int N){rep(i,N) {cout<<( (i)?" ":"" ); _cout(v[i]);} cout<<"\n";} template inline void vector_debug(const vector &v,int N=-1){cout << "{"; int M=(N == -1) ? sz(v) : N; rep(i,M) {cout<<( (i)?", ":"" ); _cout(v[i]);} cout<<"}";} template inline void vector_debug(C v[], int N){cout << "{"; rep(i,N) {cout<<((i)?", ":""); _cout(*(v+i));} cout<<"}";} void dbg_out(){cout << endl;} template void dbg_out(const T &t,U ...u){ _cout(t); if(sizeof...(u)) cout << ", "; dbg_out(u...);} template void dbg_out(const vector &v,U ...u){vector_debug(v); if(sizeof...(u)) cout << ", "; dbg_out(u...);} template void dbg_out(const vector> &v,U ...u){cout << "{ "; rep(i,sz(v)) {if(i)cout<<", "; vector_debug(v[i]);} cout << " }"; if(sizeof...(u)) cout << ", "; dbg_out(u...);} template inline C vmax(const vector &v){C n=v[0]; rep(i,sz(v)) amax(n,v[i]); return n;} template inline C vmax(C v[], int N){C n=v[0]; rep( i , N ) amax(n,v[i]); return n;} template inline C vmin(const vector &v){C n=v[0]; rep(i,sz(v)) amin(n,v[i]); return n;} template inline C vmin(C v[], int N){C n=v[0]; rep( i , N ) amin(n,v[i]); return n;} void die(string s){out(s); exit(0);} //////////// /// main /// //////////// // 1からNまでの素数を判定するライブラリ // A[i] == 1 <-> iは素数 void prime(vi& A,int N){ rep(i,N + 1) A[i] = 1; A[0] = 0; A[1] = 0; for(int i=2 ; i*i <= N ; i++){ if(A[i]){ for(int j=2; i*j <= N; j++){ A[i*j] = 0; } } } } // セグ木 template struct ST{ int size; vector seg; F func; ST(int N,F func): func(func){ size = 1; while(size < N) size <<= 1; seg.assign(2 * size, UNIT); build(); } ST(const vector &v,F func) : func(func){ // initialize int N = (int)v.size(); size = 1; while(size < N) size <<= 1; seg.resize(2 * size); // set for(int i=0;i < N; i++){ seg[i + size] = v[i]; } build(); } void set(int k,T& x){ seg[k + size] = x; } void build(){ for(int k=size-1; k>0; k--){ seg[k] = func(seg[2 * k] , seg[2 * k + 1]); } } void update(int k, T& x){ k += size; seg[k] = x; while(k >>= 1){ seg[k] = func(seg[2 * k] , seg[2 * k + 1]); } } T query(int a, int b){ T L = UNIT, R = UNIT; for(a+=size,b+=size; a>=1,b>>=1){ if(a & 1) L = func(L,seg[a++]); if(b & 1) R = func(seg[--b],R); } return func(L, R); } T operator[](const int &k) const{ return seg[k + size]; } }; auto f = [](int a,int b){ return a + b; }; int main(){ ini(N); vi a(N); in(a,N); ini(Q); vi P(Q),L(Q),R(Q); rep(i,Q) in(P[i],L[i],R[i]); vi A(2001); prime(A , 2000); vi lst; lst.reserve(1000); int nyanya = 0; rep(i,2001) if(A[i] == 1) { A[i] = nyanya++; lst.pb(i); } trc(sz(lst)); vvi data(N , vi(303 , 0)); rep(i,N){ rep(j,303){ while(a[i] % lst[j] == 0){ data[i][j]++; a[i] /= lst[j]; } } } //out("hoe"); vector< ST > st(303, ST(N,f) ); rep(i,303) rep(j,N){ st[i].set(j , data[j][i]); } rep(i,303) st[i].build(); rep(i,Q){ int flg = 1; for(int nya=2;nya*nya<=P[i];nya++){ if(P[i] % nya == 0){ int cur = st[A[nya]].query(L[i]-1,R[i]); trc(nya , cur); while(P[i] % nya == 0){ if(cur == 0) {flg = 0; break;} P[i] /= nya; cur--; } } if(flg == 0) break; } trc(P[i]); if(P[i] != 1){ int nyaa = P[i]; int curr = st[A[nyaa]].query(L[i]-1,R[i]); if(curr == 0) flg = 0; } out(flg ? "Yes" : "NO"); } }