#P9551. Defeating Bosses
Defeating Bosses
Defeating Bosses
Little X is about to face n bosses. For each boss i, he has already decided on a method bi (either 1 or 2) to challenge the boss. The rules are as follows:
- If he chooses method 1 (solo), he defeats boss i on his own and obtains ki,0 pieces of rare metal. In this case, the rewards for the other theoretical roles are defined by a guarantee:
\( k_{i,0} = k_{i,1} = k_{i,2} \). - If he chooses method 2 (cooperative with Little Y), then ideally Little X should get ki,1 pieces and Little Y should get ki,2 pieces of rare metal. However, since the boss's strength is independent of the number of fighters, the system awards both players ki,0 pieces. In addition, the rewards satisfy the relation: \[ \frac{1}{k_{i,0}} = \frac{1}{k_{i,1}} + \frac{1}{k_{i,2}}. \] It can be shown that if all values are positive integers then for method 2 the solutions \( (k_{i,0}, k_{i,1}, k_{i,2}) \) obey the equation \[ (k_{i,1}-k_{i,0})(k_{i,2}-k_{i,0}) = k_{i,0}^2, \] so that for a given choice of ki,0 the number of choices for \( (k_{i,1}, k_{i,2}) \) equals the number of positive divisors of \( k_{i,0}^2 \) (denoted by \(\tau(k_{i,0}^2)\)).
Overall, Little X will defeat all bosses and obtain a total of \[ m = \sum_{i=1}^{n} k_{i,0}. \] You are given q queries. In each query a positive integer m is provided. For each query, determine the total number of possible assignments of positive integers \( k_{i,0} \) (and corresponding \( k_{i,1}, k_{i,2} \) as above) for all bosses such that the total pieces sum to m. When boss i uses method 1, there is exactly 1 way (since \( k_{i,0}=k_{i,1}=k_{i,2} \)). When boss i uses method 2, for a chosen k_{i,0} there are \(\tau(k_{i,0}^2)\) valid assignments. Two overall assignments are considered different if at least one \( k_{i,0} \) (or one of the corresponding values) differs.
Since the answer can be very large, output it modulo 998244353.
inputFormat
The first line contains two integers n and q --- the number of bosses and the number of queries.
The second line contains n integers b1, b2, ..., bn, where each bi is either 1 or 2, indicating the method chosen for boss i.
Then follow q lines. Each of these lines contains a single positive integer m, representing the total amount of rare metal obtained.
outputFormat
For each query, output a single line containing the number of valid assignments modulo 998244353.
sample
2 3
1 2
2
3
4
1
4
7
</p>