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
questions = questions.uniq.sort
p questions


questions.each do |q|
  # select_card = []
  # counter = 0
  # while comparison < card.length-1 do
  #   counter += 1
  #   comparison = counter*q

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

  puts remainder.max
end