number_cards, number_questions = gets.split.map{ |i|
  i.to_i
}
number_cards = 300000 if number_cards > 300000
number_questions = 10000 if number_questions > 10000

counter = 0
cards = gets.split.map{ |i|
  counter += 1
  i.to_i
  break if counter == 300000
}

questions = [30000]
number_questions.times do
  questions << gets.to_i
end

questions.each do |q|
  remainder = cards.map do |c|
    c % q
  end

  puts remainder.max
end