#P6756. Prime Reduction Operations

    ID: 19964 Type: Default 1000ms 256MiB

Prime Reduction Operations

Prime Reduction Operations

Given an integer \(n\) and a list of \(m\) primes \(p_1,p_2,\dots,p_m\), you can perform any number of operations. In each operation, you choose a prime \(p_i\) from the list and update \(n\) as follows:

\[ n \to \left\lfloor \frac{n}{p_i} \right\rfloor \times p_i \]

This operation subtracts the remainder of \(n\) when divided by \(p_i\) (if the remainder is positive). Note that if \(n\) is exactly divisible by \(p_i\), this operation makes no change.

Your goal is to reduce \(n\) to 0 using the minimum number of operations. If it is impossible to do so, output oo.

To increase the challenge, you will be given \(Q\) queries, each providing a different value of \(n\).

inputFormat

The first line contains two integers \(m\) and \(Q\): the number of primes in the list and the number of queries.

The second line contains \(m\) space-separated primes \(p_1, p_2, \dots, p_m\).

Each of the following \(Q\) lines contains a single integer \(n\), representing a query.

outputFormat

For each query, output the minimum number of operations required to reduce \(n\) to 0. If it is impossible, output oo.

sample

3 3
2 3 7
10
6
3
2

oo 2

</p>