### main

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

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

qn.times do
  max_rem = 0

  q = gets.strip.to_i

  qi = q - 1
  while qi <= max_c
    i0 = 0
    i1 = n - 1

    while i0 <= i1
      i2 = (i0 + i1) / 2
      if cards[i2] == qi
        i0 = i1 = i2
        break
      elsif cards[i2] > qi
        i1 = i2 - 1
      else
        i0 = i2 + 1
      end
    end

    i0 = n - 1 if i0 >= n
    while i0 < n - 1 && cards[i0] < qi
      i0 += 1
    end
    while i0 > 0 && cards[i0] > qi
      i0 -= 1
    end

    rem = cards[i0] % q
    max_rem = rem if max_rem < rem

    qi += q
  end

  puts max_rem
end