#abc290f. F - Maximum Diameter
F - Maximum Diameter
Score : points
问题描述
对于一个长度为 的正整数序列 ,我们定义 如下:
- 如果存在一棵具有 个顶点的树,其第 个 顶点的度数为 ,则称这棵树为好树。若存在这样的好树,则 为该好树的最大直径;若不存在好树,则 。
此处,两顶点之间的距离是指从一个顶点到另一个顶点所必须经过的最少边数,而树的直径则是任意两个顶点间距离的最大值。
求所有可能的正整数序列 (长度为 )上 的和,并对 取模。可以证明 的总和是一个有限值。
给定 组测试用例,请分别计算每组的答案。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
For a sequence of length consisting of positive integers, we define as follows:
- A tree with vertices is said to be good if and only if the degree of the -th vertex is . If a good tree exists, is the maximum diameter of a good tree; if it doesn't, .
Here, the distance between two vertices is the minimum number of edges that must be traversed to travel from one vertex to the other, and the diameter of a tree is the maximum distance between two vertices.
Find the sum, modulo , of over all possible sequences of length consisting of positive integers. We can prove that the sum of is a finite value.
Given test cases, find the answer for each of them.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format, where denotes the -th test case:
Each test case is given in the following format:
Output
Print lines.
The -th line should contain the answer to the -th test case.
Sample Input 1
10
2
3
5
8
13
21
34
55
89
144
Sample Output 1
1
6
110
8052
9758476
421903645
377386885
881422708
120024839
351256142
If ,
for example,
- when , there is no tree with three vertices whose degrees are , and , so .
- When , the only possible tree is illustrated below. The diameter of this tree is , so .
For , we have ; for other , we have . Thus, the answer is .
update @ 2024/3/10 12:07:32