int lg2[maxn], pw2[lg2maxn], ansi[maxn]; vi rmq[maxn][lg2maxn], ans[maxn], p; vector<double> lnp;
voidinit() { for (int i = 2; i != maxn; ++i) lg2[i] = lg2[i >> 1] + 1; for (int i = 0; i != lg2maxn; ++i) pw2[i] = 1 << i; for (int i = 2; i <= 60; ++i) { bool prime = true; for (int j = 2; prime && j * j <= i; ++j) if (!(i % j)) prime = false; if (prime) p.push_back(i), lnp.push_back(log((double)i)); } fill(ans, ans + maxn, vi(p.size(), 7)); }
vi lcm(const vi& a, const vi& b) { vi res(p.size()); for (int i = 0, i_ = p.size(); i != i_; ++i) res[i] = max(a[i], b[i]); return res; }
vi intvlcm(int l, int r) { int s = lg2[r - l]; returnlcm(rmq[l][s], rmq[r - pw2[s]][s]); }
vi itov(int x) { vi res(p.size(), 0); for (int i = 0, i_ = p.size(); i != i_; ++i) while (!(x % p[i])) ++res[i], x /= p[i]; return res; }
intvtoi(const vi& x) { ll res = 1ll; for (int i = 0, i_ = p.size(); i != i_; ++i) for (int j = x[i]; j--;) res = (res * p[i]) % mod; return res; }
boolcmp(const vi& a, const vi& b) { double x = 0.0, y = 0.0; for (int i = 0, i_ = p.size(); i != i_; ++i) x += lnp[i] * a[i], y += lnp[i] * b[i]; return x < y; }
intmain() { init(); int n, q; scanf("%d%d", &n, &q); for (int i = 0, t; i != n; ++i) scanf("%d", &t), rmq[i][0] = itov(t); for (int j = 1; j <= lg2[n]; ++j) for (int i = n - pw2[j]; i != -1; --i) rmq[i][j] = lcm(rmq[i][j - 1], rmq[i + pw2[j - 1]][j - 1]); //////////////////////////////// for (int l = 0; l != n; ++l) { vi cur = rmq[l][0]; for (int r = l; r != n;) { cur = lcm(cur, rmq[r][0]); for (int k = lg2[n - r]; k != -1; --k) if (r + pw2[k] <= n && lcm(cur, rmq[r][k]) == cur) r += pw2[k]; ans[r - l] = min(ans[r - l], cur, cmp); } } //////////////////////////////// for (int x; q--;) { scanf("%d", &x); printf("%d\n", ansi[x] ? ansi[x] : (ansi[x] = vtoi(ans[x]))); } }