#P7704. 「MCOI-09」Greedy Deletion

「MCOI-09」Greedy Deletion

Description

Positive integers less than or equal to nn form the set Sn={1,2,,n}S_n=\{1,2,\dots,n\}.

The cost to delete the element with value ii is iki^k, and each element can be deleted at most once.

Given positive integers nn and kk, find: what is the minimum cost to make the product of all elements in SnS_n a perfect square? Output the answer modulo 998244353998244353.

Note that you need to minimize the cost first, then take modulo 998244353998244353, rather than minimizing the cost after taking modulo 998244353998244353.

You need to answer TT queries, and all queries share the same kk.

Input Format

The first line contains three positive integers TT, kk, and maxn\max n, representing the number of queries, the given kk, and the maximum nn.

The next TT lines each contain one positive integer nn.

Output Format

Output TT lines. On the ii-th line, output the answer for the ii-th query.

2 2 6
1
6
0
25

Hint

Explanation for Sample 1

For n=1n=1, the product of S1S_1 is a perfect square, so no deletion is needed.

For n=6n=6, you can delete 55 to make the product of S6S_6 a perfect square.

Constraints

  • Subtask 1 (7 pts): maxn20\max n\le 20.
  • Subtask 2 (37 pts): maxn1000\max n\le 1000.
  • Subtask 3 (11 pts): T1000T\le 1000.
  • Subtask 4 (45 pts): no additional constraints.

For 100%100\% of the testdata, 1maxn5×1061\le \max n\le 5\times 10^6, 1T5×1051\le T\le 5\times 10^5, 1k<9982443531\le k< 998244353.

It is guaranteed that 1nmaxn1\le n\le \max n.

Translated by ChatGPT 5