Divisible by At Least One
You are given k positive integers m_1, m_2, …, m_k and q queries. Each query is a positive
integer N: count how many integers x with 1 ≤ x ≤ N are divisible by at least one of the
m_i.
The m_i need not be distinct, and one may divide another.
Input
The first line contains two integers k and q (1 ≤ k ≤ 15, 1 ≤ q ≤ 2000).
The second line contains k integers m_1, …, m_k (1 ≤ m_i ≤ 10^9).
Each of the next q lines contains one integer N (1 ≤ N ≤ 10^18).
Output
For each query, print on its own line the number of integers in [1, N] divisible by at least one
m_i. The answer never exceeds 10^18, so it fits in a signed 64-bit integer.
Notes
In the first example, the numbers up to 12 divisible by 4 or 6 are 4, 6, 8 and 12. Note that 12 is
divisible by both but is counted once. No number in [1, 1] qualifies. Up to 24 there are 6
multiples of 4 and 4 multiples of 6, and 12 and 24 are in both lists, so the answer is 6 + 4 − 2 = 8.
In the second example, every multiple of 4 is already a multiple of 2, and the repeated 2 changes
nothing, so the answer is the number of even integers up to N.