#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n,m;
	cin>>n>>m;
	vi in(n);
	rep(i,n)scanf("%d",&in[i]);
	sort(all(in));
	in.pb(inf);
	while(m--){
		int a;scanf("%d",&a);
		int ma=0;
		int c=in[0]/a+1;
		while(1){
			int t=lower_bound(all(in),c*a)-in.begin();
			if(t==0)continue;
			ma=max(ma,in[t-1]%a);
			if(t==n)break;
			c++;
		}
		printf("%d\n",ma);
	}
}