#P10269. 实力派

    ID: 11374 远端评测题 1000~1500ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数论素数判断,质数,筛法最大公约数 gcd莫比乌斯反演

实力派

Background

Problem Description

There are nn OIers from all over the country who form a team called "实力派" (shílìpài). Each person has a strength value aia_i. There are mm contests that send them invitations. In the ii-th contest, they are required to form a team of kik_i people to participate. To decide whether they should join a contest, they came up with the following two measures of strength:

  • Define the xx-th order minimum strength as the number of ways to choose xx people from these nn people such that the gcd=1\gcd=1 of the chosen xx people's strength values;

  • Define the xx-th order maximum strength as the sum of the gcd\gcd of the chosen xx people over all possible choices.

For each contest, please tell them the kik_i-th order minimum strength and maximum strength for that contest. Also, to keep others from understanding, you need to take the answers modulo a secret modulus pp.

Input Format

The first line contains three integers n,m,pn,m,p, representing the number of team members, the number of contests, and the secret modulus, respectively.

The second line contains nn integers. The ii-th integer represents the strength value aia_i of the ii-th person.

The next mm lines each contain one integer kik_i, meaning the required number of participants for the ii-th contest.

Output Format

Output mm lines. The ii-th line contains two integers mini,maximin_i,max_i, representing the minimum strength and maximum strength in the ii-th contest, with answers taken modulo pp.

4 4 998244353
8 15 12 6
2
3
4
5
1 19
2 7
1 1
0 0
6 4 19260817
11 45 14 19 19 810
2
1
2
2
12 78
0 918
12 78
12 78
8 3 19491001
3 2 2 3 1 2 1 2
5
3
4
56 56
52 60
69 71

Hint

Sample 1\mathbf{1} Explanation

In the first contest, they need to choose 22 people. Only the choice (8,15)(8,15) has gcd=1\gcd=1, so the minimum strength is 11. The sum of gcd\gcd over all choices is 1919, so the maximum strength is 1919.

In the second contest, they need to choose 33 people. There are two choices with gcd=1\gcd=1: (8,15,12)(8,15,12) and (8,15,6)(8,15,6). Therefore, the minimum strength is 22. The sum of gcd\gcd over all choices is 77, so the maximum strength is 77.

Constraints

For all data, 1n,m,ki2×1051\leq n,m,k_i\leq 2\times 10^5, 1ai1061\leq a_i\leq 10^6, 107p10910^7\leq p\leq 10^9, and pPp\in \mathbb{P}.

This problem has a total of 3030 test points and uses bundled tests. The subtasks and test point distribution are as follows:

Subtask ID Test Point ID Special Property Score Time Limit
00 141\sim 4 n20n\leq 20 1010 1s1s
11 585\sim 8 n,ai300n,a_i\leq 300
22 9129\sim 12 ki2k_i\leq 2 2020 1.5s1.5s
33 131613\sim 16 ai3a_i\leq 3 1010 1s1s
44 172217\sim 22 ai105a_i\leq 10^5 2020
55 233023\sim 30 No special property 3030 1.5s1.5s

Hint

P\mathbb{P} denotes the set of all prime numbers, and gcd\gcd denotes the greatest common divisor.

Translated by ChatGPT 5