atcoder#ABC290F. [ABC290F] Maximum Diameter
[ABC290F] Maximum Diameter
Score : points
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.
10
2
3
5
8
13
21
34
55
89
144
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 .