#P3784. [SDOI2017] 遗忘的集合
[SDOI2017] 遗忘的集合
Description
Little Q posted a bounty on his personal homepage: collect a non-empty set containing only positive integers, each not exceeding , and satisfying some additional conditions.
As is well known, for any positive integer not exceeding , we can easily compute the number of ways to express as a sum of elements from . Here, in any representation, each number may be used multiple times, and the order of numbers is ignored.
For example, when , we can compute .
Another example: when , we can compute .
The trouble is that Little Q has forgotten which elements are in . Fortunately, he recorded all the values of on a storage device, and he hopes you can use this information to reconstruct the original .
Specifically, he wants you to find a non-empty set of positive integers, each at most , such that for every , the number of ways to represent as a sum of elements from is congruent to modulo , where is a prime stored on the device. He guarantees that such an exists.
However, Little Q believes the stored information is not enough to recover a unique ; that is, there may be multiple such sets . So he wants the lexicographically smallest one among all solutions.
For two different sets and that satisfy the conditions, we say is lexicographically smaller than if and only if there exists a non-negative integer such that the first smallest elements of are exactly the same as those of , and either has exactly elements and has at least elements, or both and have at least elements and the -th smallest element of is smaller than that of .
Input Format
The first line contains two integers and , where is prime.
The second line contains integers , as defined in the statement.
It is guaranteed that in each line adjacent integers are separated by exactly one space, and there is no trailing space at the end of any line.
Output Format
Output two lines describing the lexicographically smallest solution. The first line contains an integer , the number of elements in . The second line contains positive integers , which are the elements of sorted in ascending order.
You must ensure that in each output line, adjacent integers are separated by exactly one space, and there is no trailing space at the end of any line.
5 1000003
1 2 3 5 7
5
1 2 3 4 5
9 1000003
1 2 2 3 4 5 6 7 8
3
1 2 5
Hint
For of the testdata, we have , , .

Translated by ChatGPT 5
京公网安备 11011102002149号