#P9551. 「PHOI-1」斗之魂

    ID: 10797 远端评测题 1000~1800ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学数论O2优化素数判断,质数,筛法快速数论变换 NTT

「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 nn BOSSes. For the ii-th BOSS, he can choose one of the following two ways:

  1. Defeat the ii-th BOSS alone and obtain ki,0k_{i,0} pieces of rare metal, and it is guaranteed that ki,0=ki,1=ki,2k_{i,0}=k_{i,1}=k_{i,2}.
  2. Defeat the ii-th BOSS together with Little Y. Little X should obtain ki,1k_{i,1} pieces of rare metal, and Little Y should obtain ki,2k_{i,2} 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 ki,0k_{i,0} 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 bib_i to defeat the ii-th BOSS. However, due to some factors, Little X has qq queries. Each query gives a positive integer mm, which is the total number of rare metals Little X obtains after defeating all BOSSes. It is known that ki,0,ki,1,ki,2k_{i,0},k_{i,1},k_{i,2} are all positive integers. For each query, find the number of possible assignments of all kk values. Two assignments are considered different if and only if there exists at least one kk value that is different. Since the answer may be very large, output it modulo 998244353998244353.

Input Format

The first line contains two integers nn and qq, representing the number of BOSSes and the number of queries.

The second line contains nn positive integers bib_i, meaning that Little X uses method bib_i to defeat the ii-th BOSS.

Each of the next qq lines contains an integer mm, the total number of rare metals Little X obtains after defeating all BOSSes in this query.

Output Format

Output qq lines. The ii-th line should be the number of possible assignments of all kk values when the total rare metals obtained by Little X after defeating all BOSSes is mm, taken modulo 998244353998244353.

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 nn\le mm \le qq \le Time Limit Score
00 1010 2020 55 1s1s 88
11 3030 6060 77
22 4040 100100 10310^3 55
33 150150 500500
44 200200 50005000 10410^4 2020
55 20002000 5×1045 \times 10^4 10510^5 2525
66 1.5×1051.5 \times 10^5 2.5×1052.5 \times 10^5 1.8s1.8s 3030

For 100%100\% of the data, it is guaranteed that 1n1.5×1051 \le n \le 1.5 \times 10^5, 1m2.5×1051 \le m \le 2.5 \times 10^5, 1bi21 \le b_i \le 2, and 1q1051 \le q \le 10^5.

Sample Explanation #1:

  • When m=3m=3, the number of possible assignments of all kk values is 44.

    Type 11: $k_{1,0}=1,k_{1,1}=k_{1,2}=2,k_{2,0}=k_{2,1}=k_{2,2}=2$

    Type 22: $k_{1,0}=2,k_{1,1}=3,k_{1,2}=6,k_{2,0}=k_{2,1}=k_{2,2}=1$

    Type 33: $k_{1,0}=2,k_{1,1}=k_{1,2}=4,k_{2,0}=k_{2,1}=k_{2,2}=1$

    Type 44: $k_{1,0}=2,k_{1,1}=6,k_{1,2}=3,k_{2,0}=k_{2,1}=k_{2,2}=1$

  • When m=4m=4, the number of possible assignments of all kk values is 77.

    Type 11: $k_{1,0}=1,k_{1,1}=k_{1,2}=2,k_{2,0}=k_{2,1}=k_{2,2}=3$

    Type 22: $k_{1,0}=2,k_{1,1}=3,k_{1,2}=6,k_{2,0}=k_{2,1}=k_{2,2}=2$

    Type 33: $k_{1,0}=2,k_{1,1}=k_{1,2}=4,k_{2,0}=k_{2,1}=k_{2,2}=2$

    Type 44: $k_{1,0}=2,k_{1,1}=6,k_{1,2}=3,k_{2,0}=k_{2,1}=k_{2,2}=2$

    Type 55: $k_{1,0}=3,k_{1,1}=4,k_{1,2}=12,k_{2,0}=k_{2,1}=k_{2,2}=1$

    Type 66: $k_{1,0}=3,k_{1,1}=6,k_{1,2}=6,k_{2,0}=k_{2,1}=k_{2,2}=1$

    Type 77: $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