#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>

using namespace std;

int main(){

	int* checkTable = new int[300001];
	int* ansTable = new int[300002];
	int N,Q,tmp;

	for(int i = 1; i <= 300000; i++){
		checkTable[i] = -1;
		ansTable[i] = -1;
	}

	scanf("%d %d",&N,&Q);

	for(int i = 0; i < N; i++){
		scanf("%d",&tmp);
		checkTable[tmp] = tmp;
		ansTable[tmp+1] = tmp;
	}

	int tmp_max;

	for(int i = 1; i <= 300000; i++){
		if(checkTable[i] == -1){
			checkTable[i] = checkTable[i-1];
		}
	}

	ansTable[1] = 0;
	for(int i = 2; i <= 300000;i++){
		if(ansTable[i] == -1){
			tmp_max = 0;
			for(int k = i-1; k <= 300000; k += i){
				tmp_max = max(tmp_max,checkTable[k]%i);
				if(tmp_max == i-1)break;
			}
			ansTable[i] = tmp_max;
		}
	}

	int q;
	for(int i = 0; i < Q; i++){
		scanf("%d",&q);

		printf("%d\n",ansTable[q]);
	}
	return 0;
}