#include<bits/stdc++.h>
using namespace std;

const int maxv = 300000;
int main(){
  int n,q;
  cin >> n >> q;
  vector<int> c(n);
  for(int i=0;i<n;i++)cin >> c[i];
  c.push_back(0); c.push_back(maxv+1);
  sort(c.begin(),c.end());

  vector<int> pred(maxv+2,0);
  for(int i=0;i<n+1;i++){
    for(int j=c[i]+1;j<=c[i+1];j++){
      pred[j] = c[i];
    }
  }

  while(q--){
    int x;
    cin >> x;
    int ans = 0;
    for(int i=0;i<=maxv;i+=x)ans = max(ans, pred[i]%x);
    cout << ans << endl;
  }
}