#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <fstream>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;


int a[300010];

int main(){
	int N,Q;
	cin >> N >> Q;
	for(int i = 0 ; i < N ; i++){
		int t;scanf("%d",&t);
		a[t] = t;
	}
	for(int i = 1 ; i <= 300000 ; i++){
		a[i] = max(a[i],a[i-1]);
	}
	while(Q--){
		int ans = 0;
		int t;scanf("%d",&t);
		for(int i = t ; i <= 300000 ; i += t ){
			ans = max(a[i-1]%t,ans);
		}
		ans = max(a[300000]%t,ans);
		printf("%d\n",ans);
	}
}