number_cards, number_questions = gets.split.map do |tmp|
  tmp.to_i
end

cards = []
questions = []

number = gets.split.map do |tmp|
  tmp.to_i
end
number_cards.times.with_index(0) do |i|
  cards << number[i]
end

number_questions.times do
  questions << gets.to_i
end
cards = cards.sort

remainder = []
questions.each do |q|
  replica_card = cards
  last_num = replica_card.last
  hoge = last_num % q
  hikaku = last_num - hoge

  replica_card = replica_card.select{ |x| hikaku > x }
  replica_card = replica_card.max
  puts replica_card % q

  # p cards
  # remainder = cards.map do |c|
  #   c % q
  # end

  # puts remainder.max
end