import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.range;
import std.functional;
import std.algorithm;

void main() {
    int n, q; readf("%d %d\n", &n, &q);
    auto c = stdin.readln.chomp.split(" ").map!(to!int).array.sort;
    foreach (_; 0 .. q) {
        int query; readf("%d\n", &query);
        auto a = c.assumeSorted;
        int m = 0;
        for (int x = query; x <= c.back + query; x += query) {
            //writeln(x, "\t", a.lowerBound(x).back);
            m = max(m, a.lowerBound(x).back % query);
            if (m == query - 1) break;
        }
        m.writeln;
    }
}