#include <cstdio>
#include <cstring>

int N,Q;
int map[300005]={};
int  cal[300005]={};
int main(void){
	memset(cal,-1,sizeof(cal));
	int i,j,a,b,c;
	scanf("%d%d",&N,&Q);
	for(i=0;i<N;i++){
		scanf("%d",&a);
		map[a]=1;
	}
	a=-1;
	for(i=0;i<300005;i++){
		if(map[i]==1)a=i;
		cal[i]=a;
	}

	int ma,q;
	for(c=0;c<Q;c++){
		scanf("%d",&q);
		ma=0;
		i=300000;
		while(cal[i]!=-1 && i>=0){
			i=cal[i];
			ma=(ma<(i%q))?(i%q):ma;
			i=i-(i%q)-1;
		}
		printf("%d\n",ma);
	}
	return 0;
}
			