QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 128 MB Total points: 100

#4696. 猜数游戏

統計

黑板上写有 $n$ 个互不相等且都小于 $p$ 的正整数 $a_1, a_2, \cdots, a_n$。小 J 想用这些数字和小 M 玩一个猜数游戏。

游戏规则十分简单:游戏开始时,小 J 会从这些数字中随机选择若干个让小 M 来猜,而小 M 则可以通过若干次询问来确定小 J 选择了哪些数字。

每一次询问的模式如下:小 M 可以任意指定一个数字 $a_k$,若它是小 J 所选择的数字之一,则小 J 会告诉小 M 他所选择的数字中所有能表示成 $(a_k)^m \bmod p$ 的数,其中 $m$ 是任意正整数,$\bmod$ 表示求二者做带余除法后的余数。反之,若 $a_k$ 没有被小 J 选中,则小 J 只会告诉小 M $a_k$ 没有被选中。

游戏会在小 M 确定小 J 所选中的所有数字后立刻结束。

例如,若 $n=4$,$p=7$,数字 $\{a_n\}$ 按下标顺序依次为 $\{1, 3, 4, 6\}$,小 J 选定的数字为 $\{1, 4, 6\}$,一种可能的游戏进行的过程(并非是最优过程)如下:

小 M 的询问 小 J 的反馈
$a_2 = 3$ $a_2$ 没有被选中
$a_4 = 6$ $6(= 6^1 \bmod 7)$,$1(=6^2 \bmod 7)$
$a_3 = 4$ $4(= 4^1 \bmod 7)$,$1(=4^3 \bmod 7)$

$3$ 次询问后小 J 所选出的所有数都已被小 M 确定,游戏结束。

小 M 还有作业没有写完,因此他需要对游戏进行的时间进行评估。他想知道为了使游戏结束,他所需要做出询问的最小次数的期望 $S$ 是多少。

为了避免精度误差,你需要输出答案乘 $(2^n - 1)$ 后模 $998244353$ 的余数。在本题中,你可以认为小 J 每次在选数时会在集合 $\{a_1, a_2, \cdots, a_n\}$ 的全部非空子集中等概率地选择一个,在这个前提下可以证明 $(2^n - 1) \times S$ 一定是一个整数。

输入格式

第一行两个正整数 $n$ 和 $p$。

第二行 $n$ 个正整数,依次表示 $a_1, a_2, \cdots, a_n$。

输出格式

仅一行一个整数表示答案。

样例数据

样例 1 输入

4 7
1 3 4 6

样例 1 输出

17

样例 1 解释

下表给出了小 J 所选的子集与小 M 最小询问次数的关系:

小 J 所选的子集 最优的询问集合
$\{1\}$ $\{1 \}$
$\{3\}, \{3, 4\}, \{3, 6\}, \{3, 4, 6\}, \{1, 3\}, \{1, 3, 4\}, \{1, 3, 6\}, \{1, 3, 4, 6\}$ $\{3\}$
$\{4\}, \{1, 4\}$ $\{4\}$
$\{6\}, \{1, 6\}$ $\{6\}$
$\{4, 6\}, \{1, 4, 6\}$ $\{4,6\}$

因此最小询问次数的期望 $S = \frac{17}{15}$。

样例 2 输入

8 9
1 2 3 4 5 6 7 8

样例 2 输出

532

样例 3

见下发文件中的 game3.ingame3.ans

子任务

对于所有测试点:$1 \leq n \leq 5000$,$3 \leq p \leq 10^8$,$1 \leq a_i < p\ (1 \leq i \leq n)$ 且 $a_i$ 两两不同。

对于所有编号为奇数的测试点,保证 $p$ 是一个素数;对于所有编号为偶数的测试点,保证存在奇素数 $q$ 和正整数 $k > 1$ 使得 $p = q^k$。

测试点编号 $n\leq$ $p\le$ 特殊性质 测试点编号 $n\leq$ $q\le$ 特殊性质
$1$ $10$ $100$ $2$ $10$ $100$
$3$ $10$ $100$ $4$ $10$ $100$
$5$ $200$ $5000$ $6$ $200$ $5000$
$7$ $300$ $10^6$ $8$ $300$ $10^6$
$9$ $300$ $10^6$ A $10$ $300$ $10^6$ B
$11$ $5000$ $10^7$ A $12$ $5000$ $10^7$
$13$ $5000$ $10^7$ $14$ $5000$ $10^7$
$15$ $5000$ $10^8$ A $16$ $5000$ $10^8$ B
$17$ $5000$ $10^8$ $18$ $5000$ $10^8$
$19$ $5000$ $10^8$ $20$ $5000$ $10^8$

特殊性质 A:在模 $p$ 意义下 $3^i\ (1 \leq i \leq p - 1)$ 两两不同余。

特殊性质 B:对所有的 $1 \leq i \leq n$ 都有 $(a_i, p) > 1$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.