### main

n, qn = gets.strip.split(' ').map{|s| s.to_i}

cards = gets.strip.split(' ').map{|s| s.to_i}.sort

cmap = []
c0 = 0
for i in (0...n)
  c1 = cards[i]
  for j in (c0...c1)
    cmap[j] = c0
  end
  c0 = c1
end
cmap[c0] = c0
max_c = c0

qn.times do
  q = gets.strip.to_i

  max_rem = 0
  qi = q - 1

  while qi <= max_c
    rem = cmap[qi] % q
    max_rem = rem if max_rem < rem

    qi += q
  end

  puts max_rem
end