#include <bits/stdc++.h>
#define pii pair<int, int>
#define f first
#define s second
using namespace std;
int dp[10069];
vector<int> mk[10069];
int st[10069];
unordered_map<int, int> id;
int a[10069];
int mx = 1e7;
struct cha{
int opr, id, num;
bool operator < (const cha& o) const{
return opr > o.opr;
}
};
signed main(){
cin.tie(0); ios::sync_with_stdio(0);
int m, q; cin >> m >> q;
int X = 0;
for(int i=1; i<=m; i++){
cin >> a[i];
X = max(X, a[i]);
id[a[i]] = i;
}
for(int i=1; i<=m; i++){
for(int j=a[i]; j<=mx; j+=a[i]){
mk[j].push_back(id[a[i]]);
}
}
priority_queue<cha> pq;
for(int i=1; i<=1e7; i++){
if(i < X) {
dp[i] = 1;
// if(i==3) cout << "Three: " << mk[i].size() << "X\n";
for(int p : mk[i]){
st[p] = i;
pq.push({1, p, i});
// cout << i << "Push\n";
}
continue;
}
priority_queue<cha> tmp;
while(!pq.empty()){
auto[opr, id, num] = pq.top();
int gg = 0;
for(int p: mk[i]) if(p == id) {gg=1; break;}
if(st[id] != num) {
// cout << num << "POP\n";
pq.pop();
}
else if(gg){
tmp.push({opr, id, num}); pq.pop();
// cout << i << "same\n";
}
else{
break;
}
}
if(pq.empty()) {
dp[i] = -1;
// if(i==4 && !tmp.empty()) cout << tmp.top().num << "S\n";
while(!tmp.empty()){
pq.push(tmp.top()); tmp.pop();
}
continue;
}
// if(i==5) cout << pq.top().opr << ' ' << pq.top().num << "Five\n";
dp[i] = pq.top().opr + 1;
for(int p : mk[i]){
st[p] = i;
pq.push({dp[i], p, i});
// cout << i << ' ' << dp[i] << "PU\n";
}
while(!tmp.empty()){
pq.push(tmp.top()); tmp.pop();
}
// cout << i << ' ' << pq.top().num << ' ' << pq.top().opr << "TOP\n";
}
// for(int i=1; i<=10; i++) cout << i << ' ' << dp[i] << "A\n";
while(q--){
int x; cin >> x;
if(dp[x] == -1) cout << "oo\n";
else cout << dp[x] << '\n';
}
return 0;
}
/*
2 2
2 3
5
6
*/