
import std.stdio, std.string, std.array, std.algorithm, std.conv;

void main() {
  for(int n, q; readf("%d %d\n", &n, &q);) {
    int[] arr = readln.chomp.split(" ").map!(to!int).array;
    int limit = arr.reduce!(max) + 1;
    int[] table = new int[](limit);
    foreach(i; arr) table[i] = i;
    for(int i = 1; i < limit; i++) {
      table[i] = max(table[i], table[i - 1]);
    }
    for(int i = 0; i < q; i++) {
      int query, ans = 0;
      readf("%d\n", &query);

      for(int j = query; j < limit; j += query) {
        ans = max(ans, table[j - 1] % query);
      }
      ans = max(ans, table[limit - 1] % query);
      writeln(ans);
    }
  }
}