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

int main(){
  int n, q;
  cin >> n >> q;

  bool memo[300010] = {};
  int mn[300010] = {};

  int c;
  for(int i = 0;i < n;i++){
    cin >> c;
    memo[c] = true;
  }


  for(int i = 1;i <= 300000;i++){
    if(memo[i]) mn[i] = i;
    else mn[i] = mn[i-1];
  }

  int qq;
  for(int p = 0;p < q;p++){
    cin >> qq;
    int ans = mn[300000] % qq;
    for(int i = qq;i <= 300000;i += qq){
      ans = max(ans, mn[i-1] % qq);
    }
    cout << ans << endl;
  }

  return 0;
}

