#P9551. 「PHOI-1」斗之魂
「PHOI-1」斗之魂
Background
The testdata for this problem has been strengthened.
After a busy day, Little X started playing a game called Soul of Battle.

Problem Description
Little X needs to defeat BOSSes. For the -th BOSS, he can choose one of the following two ways:
- Defeat the -th BOSS alone and obtain pieces of rare metal, and it is guaranteed that .
- Defeat the -th BOSS together with Little Y. Little X should obtain pieces of rare metal, and Little Y should obtain pieces of rare metal. However, the BOSS’s strength does not change with the number of players, and the fight becomes relatively easier, so the system determines that both players actually obtain pieces of rare metal. It is guaranteed that $\dfrac{1}{k_{i,0}}=\dfrac{1}{k_{i,1}}+\dfrac{1}{k_{i,2}}$.
Little X has already planned to use method to defeat the -th BOSS. However, due to some factors, Little X has queries. Each query gives a positive integer , which is the total number of rare metals Little X obtains after defeating all BOSSes. It is known that are all positive integers. For each query, find the number of possible assignments of all values. Two assignments are considered different if and only if there exists at least one value that is different. Since the answer may be very large, output it modulo .
Input Format
The first line contains two integers and , representing the number of BOSSes and the number of queries.
The second line contains positive integers , meaning that Little X uses method to defeat the -th BOSS.
Each of the next lines contains an integer , the total number of rare metals Little X obtains after defeating all BOSSes in this query.
Output Format
Output lines. The -th line should be the number of possible assignments of all values when the total rare metals obtained by Little X after defeating all BOSSes is , taken modulo .
2 2
2 1
3
4
4
7
5 5
1 2 1 2 1
4
6
8
10
12
0
9
119
630
2210
Hint
This problem uses bundled tests.
Constraints
| Subtask | Time Limit | Score | |||
|---|---|---|---|---|---|
For of the data, it is guaranteed that , , , and .
Sample Explanation #1:
-
When , the number of possible assignments of all values is .
Type : $k_{1,0}=1,k_{1,1}=k_{1,2}=2,k_{2,0}=k_{2,1}=k_{2,2}=2$
Type : $k_{1,0}=2,k_{1,1}=3,k_{1,2}=6,k_{2,0}=k_{2,1}=k_{2,2}=1$
Type : $k_{1,0}=2,k_{1,1}=k_{1,2}=4,k_{2,0}=k_{2,1}=k_{2,2}=1$
Type : $k_{1,0}=2,k_{1,1}=6,k_{1,2}=3,k_{2,0}=k_{2,1}=k_{2,2}=1$
-
When , the number of possible assignments of all values is .
Type : $k_{1,0}=1,k_{1,1}=k_{1,2}=2,k_{2,0}=k_{2,1}=k_{2,2}=3$
Type : $k_{1,0}=2,k_{1,1}=3,k_{1,2}=6,k_{2,0}=k_{2,1}=k_{2,2}=2$
Type : $k_{1,0}=2,k_{1,1}=k_{1,2}=4,k_{2,0}=k_{2,1}=k_{2,2}=2$
Type : $k_{1,0}=2,k_{1,1}=6,k_{1,2}=3,k_{2,0}=k_{2,1}=k_{2,2}=2$
Type : $k_{1,0}=3,k_{1,1}=4,k_{1,2}=12,k_{2,0}=k_{2,1}=k_{2,2}=1$
Type : $k_{1,0}=3,k_{1,1}=6,k_{1,2}=6,k_{2,0}=k_{2,1}=k_{2,2}=1$
Type : $k_{1,0}=3,k_{1,1}=12,k_{1,2}=4,k_{2,0}=k_{2,1}=k_{2,2}=1$
Translated by ChatGPT 5