number_cards = 0
number_questions = 0
remainder =[]

number_cards, number_questions = gets.split.map{ |tmp|
  tmp.to_i
}
number_cards = 300000 if number_cards > 300000
number_questions = 100000 if number_questions > 100000

cards = [number_cards]
questions = [number_questions]

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

number_questions.times do
  questions << gets.to_i
end

puts '------------------'
puts "???????????°???#{questions}"
puts "??????????????°???#{cards}"
puts '------------------'

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

  puts remainder.max
end