P28683 [洛谷] [SDOI2017] Forgotten Set
省选
题目描述

Problem Description

Little Q has posted a bounty on his personal page:征集只含正整数的非空集合 $S$,其中的每个元素都不超过 $n$,并且满足一些附加条件。

As is well known, we can easily calculate the number of ways to express any positive integer $x$ not exceeding $n$ as a sum of elements from $S$, denoted as $f(x)$. Here, we stipulate that each number can appear multiple times in any scheme, but the order of appearance is not considered.

For example, when $S = \{1, 2, 3, 4, 5\}$, we can calculate $f(2) = 2, f(3) = 3, f(4) = 5, f(5) = 7$.

Another example, when $S = \{1, 2, 5\}$, we can calculate $f(4) = 3, f(5) = 4, f(6) = 5, f(7) = 6$.

The trouble is that Little Q has forgotten the elements of $S$. Fortunately, he has recorded the values of $f(i) \bmod p$ for all $i$, where $p$ is a prime number stored in his device. Little Q hopes you can use this information to restore the original $S$.

Specifically, he wants you to find a non-empty set $S$ of positive integers, where each element does not exceed $n$, and for any $i = 1, 2, \cdots, n$, the number of ways to express $i$ as a sum of elements from $S$ modulo $p$ equals $f(i)$. He assures you that such a set $S$ exists.

However, Little Q believes that the stored information may not be sufficient to recover a unique $S$, meaning there might be multiple such sets $S$. Therefore, Little Q wants you to provide the solution with the smallest lexicographical order.

For two different sets $S_1$ and $S_2$ that meet the criteria, we consider $S_1$ to have a smaller lexicographical order than $S_2$ if and only if there exists a non-negative integer $k$ such that the first $k$ smallest elements of $S_1$ and $S_2$ are identical, and either $S_1$ has exactly $k$ elements while $S_2$ has at least $k + 1$ elements, or both $S_1$ and $S_2$ have at least $k + 1$ elements, and the $(k + 1)$-th smallest element of $S_1$ is smaller than that of $S_2$.

Input Format

The first line contains two integers $n$ and $p$, where $p$ is a prime number.

The second line contains $n$ integers $f(1), f(2), \cdots, f(n)$, as described in the problem statement.

Ensure that adjacent integers in each line are separated by exactly one space, and there are no trailing spaces at the end of each line.

Output Format

You need to output two lines to describe the solution with the smallest lexicographical order. The first line contains an integer $m (m > 0)$, indicating the number of elements in $S$. The second line contains $m$ positive integers $s_1, s_2, \cdots, s_m$, representing the sequence obtained by sorting all elements of $S$ in ascending order.

Ensure that adjacent integers in each line are separated by exactly one space, and there are no trailing spaces at the end of each line.

Sample Input and Output

Sample Input #1

5 1000003
1 2 3 5 7

Sample Output #1

5
1 2 3 4 5

Sample Input #2

9 1000003
1 2 2 3 4 5 6 7 8

Sample Output #2

3
1 2 5

Notes

For $100\%$ of the data, $1 \leq n < 2^{18}, 10^6 \leq p < 2^{30}, 0 \leq f(i) < p \quad (i = 1, 2, \cdots, n)$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 1000003 1 2 3 5 7
样例输出
5 1 2 3 4 5