#P6730. [WC2020] 猜数游戏

[WC2020] 猜数游戏

Description

There are nn pairwise distinct positive integers a1,a2,,ana_1, a_2, \cdots, a_n written on the blackboard, all smaller than pp. Little J wants to use these numbers to play a number guessing game with Little M.

The rules are very simple. At the start of the game, Little J will randomly choose some of these numbers for Little M to guess. Little M can determine which numbers Little J chose by making several queries.

Each query works as follows: Little M may specify any number aka_k. If it is one of the numbers chosen by Little J, then Little J will tell Little M all numbers among his chosen numbers that can be written as (ak)mmodp(a_k)^m \bmod p, where mm is any positive integer, and mod\bmod denotes the remainder after division. Otherwise, if aka_k was not chosen by Little J, then Little J will only tell Little M that aka_k was not chosen.

The game ends immediately after Little M has determined all numbers chosen by Little J.

For example, if n=4n=4, p=7p=7, and the numbers {an}\{a_n\} in index order are {1,3,4,6}\{1, 3, 4, 6\}, and Little J chooses {1,4,6}\{1, 4, 6\}, then one possible process (not necessarily optimal) is:

Little M's query Little J's response
a2=3a_2 = 3 a2a_2 was not chosen
a4=6a_4 = 6 6(=61mod7)6(= 6^1 \bmod 7), 1(=62mod7)1(=6^2 \bmod 7)
a3=4a_3 = 4 4(=41mod7)4(= 4^1 \bmod 7), 1(=43mod7)1(=4^3 \bmod 7)

After 33 queries, Little M has determined all numbers chosen by Little J, and the game ends.

Little M still has homework to finish, so he needs to estimate the time spent in the game. He wants to know the expected value SS of the minimum number of queries he needs to make in order to end the game.

To avoid precision errors, you need to output the remainder of the answer multiplied by (2n1)(2^n - 1) modulo 998244353998244353. In this problem, you may assume that each time Little J chooses numbers, he selects uniformly at random among all non-empty subsets of {a1,a2,,an}\{a_1, a_2, \cdots, a_n\}. Under this assumption, it can be proven that (2n1)×S(2^n - 1) \times S is always an integer.

Input Format

The first line contains two positive integers nn and pp.

The second line contains nn positive integers, representing a1,a2,,ana_1, a_2, \cdots, a_n in order.

Output Format

Output a single integer in one line, representing the answer.

4 7
1 3 4 6

17
8 9
1 2 3 4 5 6 7 8
532

Hint

Sample 1 Explanation

The table below shows the relationship between the subset chosen by Little J and the minimum number of queries for Little M:

Subset chosen by Little J Optimal set of queries
{1}\{1\}
$\{3\}, \{3, 4\}, \{3, 6\}, \{3, 4, 6\}, \{1, 3\}, \{1, 3, 4\}, \{1, 3, 6\}, \{1, 3, 4, 6\}$ {3}\{3\}
{4},{1,4}\{4\}, \{1, 4\} {4}\{4\}
{6},{1,6}\{6\}, \{1, 6\} {6}\{6\}
{4,6},{1,4,6}\{4, 6\}, \{1, 4, 6\} {4,6}\{4,6\}

Therefore, the expected minimum number of queries is S=1715S = \frac{17}{15}.

Constraints

For all test points: 1n50001 \leq n \leq 5000, 3p1083 \leq p \leq 10^8, 1ai<p (1in)1 \leq a_i < p\ (1 \leq i \leq n), and all aia_i are pairwise distinct.

For all test points with odd indices, pp is guaranteed to be a prime; for all test points with even indices, it is guaranteed that there exists an odd prime qq and an integer k>1k > 1 such that p=qkp = q^k.

Test point ID nn\leq pp\le Special property Test point ID nn\leq pp\le Special property
11 1010 100100 None 22 1010 100100 None
33 44
55 200200 50005000 66 200200 50005000
77 300300 10610^6 88 300300 10610^6
99 A 1010 B
1111 50005000 10710^7 1212 50005000 10710^7 None
1313 None 1414
1515 10810^8 A 1616 10810^8 B
1717 None 1818 None
1919 2020

Special property A: Modulo pp, 3i (1ip1)3^i\ (1 \leq i \leq p - 1) are pairwise incongruent.

Special property B: For all 1in1 \leq i \leq n, (ai,p)>1(a_i, p) > 1.

Translated by ChatGPT 5