#include #pragma GCC optimize("O3") //#define int long long using namespace std; const int X = 1000001; int f[X]; map fact(int x){ map res; while(x > 1){ res[f[x]]++; x /= f[x]; } return res; } map comb(map &a, map &b){ map res = a; for(auto t : b){ int x,y; tie(x,y)=t; res[x] += y; } return res; } signed main(){ cin.tie(0); ios::sync_with_stdio(0); for(int i = 2; i < X; i++) f[i] = i; for(int i = 2; i < X; i++) if(f[i] == i){ for(int j = i+i; j < X; j += i){ if(f[j] == j) f[j] = i; } } int n; cin >> n; vector a(n); for(int &x : a) cin >> x; int L = 1<<(int)ceil(log2(n)); vector> T(2*L); for(int i = 0; i < n; i++) T[i+L] = fact(a[i]); for(int i = L-1; i; i--) T[i] = comb(T[2*i], T[2*i+1]); int q; cin >> q; while(q--){ int s, t, k; cin >> s >> t >> k; map cur = fact(k); s--, t--; s += L, t += L; map res; while(s <= t){ if(s&1) res = comb(res,T[s++]); if(!(t&1)) res = comb(res,T[t--]); s /= 2, t /= 2; } int yes = 1; for(auto t : cur){ int x,y; tie(x,y) = t; if(res[x] < y) yes = 0; } if(yes) cout << "Yes\n"; else cout << "No\n"; } }