#include <cstdio>
#include <algorithm>

using namespace std;

int memo[300001];

int main()
{
	int n, q;
	int t, m;
	
	scanf("%d %d", &n, &q);
	
	for (int i = 0; i < n; i++){
		scanf("%d", &t);
		memo[t] = t;
	}
	
	for (int i = 1; i < 300001; i++){
		memo[i] = max(memo[i - 1], memo[i]);
	}
	
	for (int i = 0; i < q; i++){
		scanf("%d", &t);
		m = 0;
		for (int j = t - 1; j <= 300000; j += t){
			m = max(m, memo[j] % t);
		}
		m = max(m, memo[300000] % t);
		printf("%d\n", m);
	}
	
	return (0);
}