QOJ.ac

QOJ

実行時間制限: 3 s メモリ制限: 1024 MB 満点: 100

#1984. 导师

統計

Happy Tree Friends 聚在一起举行年度会议,商讨来年最重要的决定。今年,他们将建立一个导师计划,以帮助彼此更好地照顾亲友。该计划遵循如下的树状层级结构:

该计划的 $N$ 名成员按资历递增被赋予 $1$ 到 $N$ 的编号(每个编号仅分配一次)。为了使导师计划高效,编号为 $A$ 的人仅在 $A > B$ 时才能指导编号为 $B$ 的人。资历最高的 Happy Tree Friend 没有导师,而其他人都有唯一的导师。反过来,每个人最多可以指导两人。

然而,编号为 $R$ 的 Pickles 先生计划今年休假。因此,他将无法指导任何人,Happy Tree Friends 应该在编号为 $R$ 的节点为叶子节点的树中选择他们的层级结构。

为了帮助他的朋友们选择这样一棵树,Pickles 先生决定先计算有多少棵树符合他的约束。不幸的是,他很早就辍学了,因此没有学会如何处理任意大小的整数。相反,他计算模 $M$ 的结果,其中 $M$ 是一个固定的正整数:这在生活中已经足够了。

请问 Pickles 先生在统计完所有合适的树后得到的数字 $L$ 是多少?

输入格式

输入包含一行,由三个空格分隔的整数:$R, N, M$。

输出格式

输出包含一行,即符合 Pickles 先生约束的树状层级结构的数量,对 $M$ 取模后的结果 $L$。

数据范围

  • $1 \leqslant R \leqslant N \leqslant 2021$
  • $1 \leqslant M \leqslant 1\,000\,000\,000$

样例

样例输入 1

2 4 2

样例输出 1

1

说明 1

编号为 $R = 2$ 的节点在下面列出的五棵树中的三棵里是叶子节点,因此有 $3$ 棵树符合 Pickles 先生的约束。我们树的唯一有意义的特征是父子关系,它代表导师关系,因此节点没有左孩子或右孩子的概念。Pickles 先生计算模 $M = 2$ 的结果,因此他最终得到的数字为 $L = 3 \pmod 2 = 1$。

样例输入 2

2 4 3

样例输出 2

0

说明 2

Pickles 先生现在计算模 $M = 3$ 的结果,因此他最终得到的数字为 $L = 3 \pmod 3 = 0$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.