#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int N, Q, query[300010];
vector< int > card;

int main() {
	cin >> N >> Q;
	
	for_(i,0,N) {
		int c; cin >> c;
		card.push_back(c);
	}
	
	sort(card.begin(), card.end());
	
	memset(query, 0, sizeof(query));
	
	for_(q,2,300001) {
		int qq = q;
		
		while (1) {
			int lw = lower_bound(card.begin(), card.end(), qq) - card.begin() - 1;
			if (lw >= 0) query[q] = max(query[q], card[lw] % q);
			if (lw == N-1) break;
			qq += q;
		}
	}
	
	for_(i,0,Q) {
		int q; cin >> q;
		cout << query[q] << endl;
	}
}