#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for(int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const int MAXNUM = 300001;

int main()
{
    int N, Q;
    cin >> N >> Q;
    vector<int> c(MAXNUM);

    rep(i, N) 
    {
        int input;
        cin >> input;
        c[input] = input;
    }

    rep(i, MAXNUM - 1) c[i + 1] = max(c[i + 1], c[i]);

    rep(i, Q)
    {
        int q, r = 0;
        cin >> q;
        for(int i = q - 1; i < MAXNUM; i += q)
        {
            r = max(r, c[i] % q);
        }

        cout << r << endl;
    }

    return 0;
}
