#include <bits/stdc++.h>

using namespace std;

int main() {

    int n, m;
    int max_num = 0;
    int next[300001];

    fill(next, next + 300001, 0);

    cin >> n >> m;

    for(int i = 0; i < n; ++i) {
        int c;
        cin >> c;
        next[c + 1] = c;
        max_num = max(max_num, c);
    }

    for(int i = 1; i <= max_num; ++i) {
        if(!next[i]) {
            next[i] = next[i - 1];
        }
    }

    for(int i = 0; i < m; ++i) {

        int q;
        int ans, cur;

        cin >> q;

        ans = max_num % q;
        cur = max_num - (max_num % q);

        while(cur) {

            ans = max(ans, next[cur] % q);
            if(cur - q < 0) break;
            cur -= q;

        }

        cout << ans << endl;

    }

}