#P8329. Complementary Leaf Trees

    ID: 21508 Type: Default 1000ms 256MiB

Complementary Leaf Trees

Complementary Leaf Trees

A tree is called an increasing rooted tree if it has n nodes labeled 1 through n and is constructed as follows.

In the first tree, the construction is:

  1. Node 1 is the root.
  2. For every i from 2 to n, choose a parent p(i) from the set \([1,i-1]\). (That is, \(p(i) \in \{1,2,\dots,i-1\}\).)

In the second tree, the construction is:

  1. Node n is the root.
  2. For every i from 1 to n-1, choose a parent q(i) from the set \([i+1,n]\). (That is, \(q(i) \in \{i+1,i+2,\dots,n\}\).)

For any tree, we call a node a leaf if it has no child (i.e. no node selects it as its parent).

The two trees are said to be complementary in leaf pattern if for every node \(i\) (\(1\le i\le n\)) the following holds:

[ \text{if node } i \text{ is a leaf in the first tree then it is non‐leaf in the second tree,}
\text{and if it is non‐leaf in the first tree then it is a leaf in the second tree.} ]

Notice that by the construction, when \(n\ge2\), node 1 in the first tree is always non‐leaf (since \(p(2)=1\) is forced) and node \(n\) in the second tree is forced to be non‐leaf (since for \(i=n-1,\,q(n-1)=n\) is the only possibility). Thus the conditions really impose a complementary relationship for every \(i\) with \(2\le i\le n-1\).

Your task is: Given two integers \(N\) and \(M\), for every \(n\) with \(2 \le n \le N\) count the number of ways to generate two trees by the above rules such that the leaf‐pattern condition holds, and output the answer modulo \(M\). Two pairs of trees are considered different if for some node the parent in one of the trees is different.

Input Format: Two integers \(N\) and \(M\) in one line.

Output Format: Output \(N-1\) lines. The \(i\)th line (for \(i=1,2,\dots,N-1\)) contains a single integer denoting the number of valid pairs for \(n=i+1\) modulo \(M\).

Note that all formulas are in LaTeX format.

inputFormat

The input consists of a single line containing two integers \(N\) and \(M\) (with \(N\ge2\)).

outputFormat

For each \(n\) from 2 to \(N\) (in increasing order), output the number of valid pairs of trees (constructed as described) modulo \(M\), one per line.

sample

2 1000
1