#P6756. [BalticOI 2013] Brunhilda's Birthday

[BalticOI 2013] Brunhilda's Birthday

Problem Description

There is an integer nn and a prime list pp of length mm.

You may perform any number of operations. In each operation, you choose a prime pip_i, which changes nn to nnpi×pin \to \lfloor \frac{n}{p_i} \rfloor \times p_i.

Your goal is to find the minimum number of operations needed to make nn become 00. If it is impossible to make it 00, output oo.

To make it harder, you need to answer QQ queries of nn.

Input Format

The first line contains two integers m,Qm, Q.

The next line contains mm integers pp.

The next QQ lines each contain one integer nn, representing the value of nn given in each query.

Output Format

For each query, output the minimum number of operations needed to make nn become 00. If it is impossible, output oo.

2 2
2 3
5
6
3
oo

Hint

Constraints and Limits

  • For the testdata worth 2020 points, it is guaranteed that m,n,Q104m, n, Q \le 10^4.
  • For another 2020 points of testdata, it is guaranteed that Q=1Q = 1.
  • For 100%100\% of the testdata, it is guaranteed that 1m,Q1051 \le m, Q \le 10^5, 2pi1072 \le p_i \le 10^7 and pip_i is prime, and 1n1071 \le n \le 10^7.

Notes

This problem is translated from Baltic Olympiad in Informatics 2013 Day 2 T1 Brunhilda’s Birthday.

Because the translator could not find a suitable setting, this problem has a full score of 110110 points.

Translated by ChatGPT 5