### subroutines

### 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

max_c = cmap[c0] = c0

qn.times do
  q = gets.strip.to_i

  max_qi = (max_c / q + 1) * q
  for i in (max_c..max_qi)
    cmap[i] = max_c
  end

  max_rem = 0
  qi = q - 1

  while qi <= max_qi
    rem = cmap[qi] % q
    if max_rem < rem
      max_rem = rem
      break if max_rem == q - 1
    end

    qi += q
  end

  puts max_rem
end