#P5616. [MtOI2019] 恶魔之树

    ID: 6326 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP数学2019洛谷原创O2优化期望洛谷月赛

[MtOI2019] 恶魔之树

Background

Before Kirito and Eugeo went with Alice to the Northern Cave, Eugeo could only chop the Demon Tree—Gigas Cedar—every day with the Dragon Bone Axe...

Please ignore bilibili’s watermark.

Problem Description

Kirito and Eugeo felt bored chopping trees every day, so they started competing to see who could produce more “good sounds” while chopping. Gradually, they found this was still not interesting, so they changed the rules a bit based on that:

Before each person chops the tree, they will randomly get a sequence s1,s2,,sns_1, s_2, \dots, s_n of length nn. At the beginning, everyone’s score is 11. When a “good sound” occurs on the ii-th chop, the score becomes the least common multiple of the original score and sis_i, which is commonly called lcm{\rm lcm}.

Now Kirito has obtained a sequence s1,s2,,sns_1, s_2, \ldots, s_n of length nn. He wants to know his expected score if the probability of getting a “good sound” on each chop is 50%50\%.

Since Kirito does not want to see decimals, please tell Kirito the value of the answer multiplied by 2n2^n modulo pp.

Input Format

There are 22 lines in total.

The 11-st line contains 22 positive integers nn and pp, representing the length of the sequence and the given modulus. It is guaranteed that the modulus is a prime number.

The 22-nd line contains nn positive integers. The ii-th number represents sis_i.

Output Format

There is 11 line in total, containing 11 positive integer, representing the expected score multiplied by 2n2^n modulo pp.

3 998244353
1 2 3
24
10 998244353
1 2 3 4 5 6 7 8 9 10
516032

Hint

Sample Explanation 1

There are 88 possible cases in total:

  • No “good sound” occurs, the score is 11, and the probability is 18\frac{1}{8}.

  • Only the first time has a “good sound”, the score is 11, and the probability is 18\frac{1}{8}.

  • Only the second time has a “good sound”, the score is 22, and the probability is 18\frac{1}{8}.

  • Only the third time has a “good sound”, the score is 33, and the probability is 18\frac{1}{8}.

  • Only the third time does not have a “good sound”, the score is lcm(1,2)=2\operatorname{lcm}(1, 2)=2, and the probability is 18\frac{1}{8}.

  • Only the second time does not have a “good sound”, the score is lcm(1,3)=3\operatorname{lcm}(1, 3)=3, and the probability is 18\frac{1}{8}.

  • Only the first time does not have a “good sound”, the score is lcm(2,3)=6\operatorname{lcm}(2, 3)=6, and the probability is 18\frac{1}{8}.

  • Every time produces a “good sound”, the score is lcm(1,2,3)=6\operatorname{lcm}(1, 2, 3)=6, and the probability is 18\frac{1}{8}.

So the expected value is $\frac{1}{8}+\frac{1}{8}+\frac{2}{8}+\frac{3}{8}+\frac{2}{8}+\frac{3}{8}+\frac{6}{8}+\frac{6}{8}=3$.

After multiplying by 232^3, the answer is 2424.

Subtasks

This problem uses bundled test.

For 100%100\% of the data, 1n3×1051\leq n\leq 3\times 10^5, 107p1.1×10910^7 \leq p \leq 1.1 \times 10^9 and pp is a prime number, and 1si3001\leq s_i\leq 300.

This problem has 77 subtasks. The score and constraints of each subtask are as follows:

Subtask 11 (33 points): n=1n=1.

Subtask 22 (77 points): n=18n=18.

Subtask 33 (1010 points): n=100n=100, and the number of distinct positive integers in ss is at most 1818.

Subtask 44 (2020 points): n=100n=100, and there do not exist 1ijn1\leq i \neq j \leq n such that si=sjs_i=s_j. It is also guaranteed that the testdata is random.

Subtask 55 (2020 points): 1s1,s2,,sn1001\leq s_1, s_2, \ldots, s_n \leq 100.

Subtask 66 (2020 points): 1n1041\leq n \leq 10^4.

Subtask 77 (2020 points): No special constraints.


This problem is dedicated to celebrating the 10th anniversary of Sword Art Online. Seems like it is a few months late...

Source

MtOI2019 Extra Round T4

Problem setter: CYJian.

Problem reviewer: suwAKow.

Translated by ChatGPT 5