#P2183. [国家集训队] 礼物

    ID: 1154 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学WC/CTSC/集训队中国剩余定理,CRTLucas 定理

[国家集训队] 礼物

Description

Xiao E bought nn gifts from a store and plans to give them to mm people, where the number of gifts given to the ii-th person is wiw_i. Please help compute the number of ways to give out the gifts (two ways are considered different if and only if there exists a person who receives different gifts in the two ways). Since the number of ways can be very large, you only need to output the result modulo PP.

Input Format

The first line contains an integer PP, the modulus.
The second line contains two integers nn and mm, representing the number of gifts Xiao E bought and the number of recipients, respectively.
Lines 33 to (m+2)(m + 2): each line contains an integer; the integer on the (i+2)(i + 2)-th line wiw_i denotes the number of gifts given to the ii-th person.

Output Format

If there is no feasible way, output Impossible; otherwise, output a single integer representing the number of ways modulo PP.

100
4 2
1
2

12
100
2 2
1
2
Impossible

Hint

Explanation for Sample 1

Separated by /, where the parts before and after / represent the gift IDs for the first and second persons, respectively. The 1212 possible ways are as follows:

1/23 1/24 1/34
2/13 2/14 2/34
3/12 3/14 3/24
4/12 4/13 4/23

Constraints

Let P=i=1tpiciP= \prod_{i=1}^t p_i^{c_i}, where pip_i is a prime.

For 15%15\% of the testdata, n15n\leq 15, m5m\leq 5, pici105p_i^{c_i}\leq 10^5.

In the remaining 85%85\% of the testdata, about 60%60\% satisfy t2t\leq 2, ci=1c_i=1, pi105p_i\leq 10^5, and about 30%30\% satisfy pi200p_i\leq 200.

For 100%100\% of the testdata, 1n1091\leq n\leq 10^9, 1m51\leq m\leq 5, 1pici1051\leq p_i^{c_i}\leq 10^5, 1wiP1091\leq w_i \leq P\leq 10^9.

Translated by ChatGPT 5