#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    int n,q;
    int maxc = 0;
    cin >> n >> q;
    vector<int> c(n);
    REP(i,n) {
	cin >> c[i];
	maxc = max(c[i],maxc);
    }
    sort(ALL(c));
    REP(i,q){
	int m;
	int ans = 0;
	int j = 1;
	cin >> m;
	while(m*(j-1) <= maxc){
	    int l = lower_bound(ALL(c),m*j) - c.begin();
	    if(l > 0 ) ans = max(ans,c[l-1]%m);
	    ans = max(ans,c[l]%m);
	    if(l == n) ans = max(ans,c[l+1]%m);
	    j++;
	}
	cout << ans << endl;
    }
    return 0;
}