#P8329. [ZJOI2022] 树
[ZJOI2022] 树
Background
The annual ZJOI is about to be held again, but the veteran problem setter Kujou Karen suddenly had an urgent matter and had to return to the UK.
“Leave it to you all! There will definitely be no problem desu!”, after saying that, Karen ran off into the distance.
Shinobu, Alice, Aya, and Youko watched Karen leave and felt a bit at a loss. After all, there were less than three weeks left until ZJOI.
“Since this is the task Karen-chan left behind, we must work hard to finish it. After all, I am the older sister,” said Alice.
So everyone began setting problems enthusiastically. “Hopefully this is the first and also the last time,” everyone thought in unison.
At the same time, the main character of the problem was set to be Kujou Karen!
Problem Description
Kujou Karen is a girl who likes trees. She wants to generate two trees, each with nodes.
The first tree is generated as follows:
- Node is the root of the tree.
- For , choose a node from as the parent of .
The second tree is generated as follows:
- Node is the root of the tree.
- For , choose a node from as the parent of .
Kujou Karen wants that for any : if node is a leaf in the first tree, then node is a non-leaf in the second tree; if node is a non-leaf in the first tree, then node is a leaf in the second tree. A node is called a leaf if and only if no node has it as its parent.
Kujou Karen wants you to count the number of ways to generate the two trees. Specifically, you need to compute the number of ways for all . Two ways are different if and only if there exists a node in one of the trees whose parent is different in the two ways. Since the answer may be very large, you only need to output the result modulo .
Input Format
The first line contains two integers , representing the upper limit on the number of nodes in the tree and the modulus.
Output Format
Output lines, each containing one integer.
Specifically, on the -th line output the value of the answer modulo when .
5 998244353
1
2
12
120
见附件中的 tree/tree_ex2.in
见附件中的 tree/tree_ex2.ans
Hint
For all test cases: it is guaranteed that and .
The specific limits for each test case are shown in the table below:
| Test Case ID | Special Constraints | |
|---|---|---|
| None | ||
| Guaranteed that is prime | ||
| None | ||
| Guaranteed that is prime | ||
| None | ||
| Guaranteed that is prime | ||
| None | ||
| Guaranteed that is prime | ||
| None | ||
| Guaranteed that is prime |
Translated by ChatGPT 5