#include<iostream>
#include<vector>
using namespace std;

int main(void){
  int n,q;
  cin>>n>>q;
  vector<int> d(300010);
  int in;
  for(int i = 0 ; i < n ; i ++){
    cin>>in;
    d[in] = in;
  }
  for(int i = 0 ; i < 300000 ; i ++){
    if(!d[i+1])d[i+1] = d[i];
  }
  while(q--){
    cin>>in;
    
    int ret = 0;
    for(int i = in-1 ; i <= 300000 ; i +=in)ret = max(ret,d[i]%in);
    cout<<ret<<endl;
  }

}