Pyramid

For each query Q, find the Q-th smallest positive integer divisible by at least one of up to 15 given numbers, with every answer at most 10^18.

Hard8Binary searchCombinatoricsNumber theoryMathNo attempts yetTime limit2sMemory limit1024 MB

Problem

Archaeologists have deciphered the hieroglyphs carved on the walls of a pyramid. One wall lists NN sacred numbers. Every positive integer divisible by at least one of those NN numbers is sacred as well.

The writings on MM other walls say that the QiQ_i-th smallest sacred number has magic properties. The archaeologists want to know which numbers those are.

You are given positive integers A1,A2,,ANA_1, A_2, \ldots, A_N and positive integers Q1,Q2,,QMQ_1, Q_2, \ldots, Q_M. For each ii, find the QiQ_i-th smallest positive integer that is divisible by at least one of A1,A2,,ANA_1, A_2, \ldots, A_N.

Input

The first line contains two integers NN and MM. The second line contains the integers A1,A2,,ANA_1, A_2, \ldots, A_N separated by spaces. Each of the next MM lines contains one integer QiQ_i.

  • 1N151 \le N \le 15 and 1M501 \le M \le 50
  • 2Ai10182 \le A_i \le 10^{18} for every ii
  • A1×A2××AN1018A_1 \times A_2 \times \cdots \times A_N \le 10^{18}
  • 1Qi10181 \le Q_i \le 10^{18} for every ii
  • Every number in the output is at most 101810^{18}.
  • In 10% of the test cases Q1,Q2,,QM106Q_1, Q_2, \ldots, Q_M \le 10^6. In 30% of the test cases N2N \le 2.

Output

Print MM lines. Line ii contains the QiQ_i-th smallest positive integer that is divisible by at least one of A1,A2,,ANA_1, A_2, \ldots, A_N.