atcoder#ABC264H. [ABC264Ex] Perfect Binary Tree
[ABC264Ex] Perfect Binary Tree
Score : points
Problem Statement
We have a rooted tree with vertices numbered . The tree is rooted at Vertex , and the parent of Vertex is Vertex k=1,2,\dots,N$, solve the following problem:
There are ways to choose some of the vertices numbered between and so that Vertex is chosen. How many of them satisfy the following condition: the subgraph induced by the set of chosen vertices forms a perfect binary tree (with vertices for a positive integer ) rooted at Vertex ? Since the count may be enormous, print the count modulo .
What is an induced subgraph?
Let be a subset of the vertex set of a graph . The subgraph induced by this vertex set is constructed as follows:
- Let the vertex set of equal .
- Then, we add edges to as follows:
- For all vertex pairs such that , if there is an edge connecting and in , then add an edge connecting and to .
What is a perfect binary tree?
A perfect binary tree is a rooted tree that satisfies all of the following conditions:
- Every vertex that is not a leaf has exactly $2$ children.
- All leaves have the same distance from the root.
Here, we regard a graph with 1 vertex and 0 edges as a perfect binary tree, too.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th () line should contain the answer as an integer when .
10
1 1 2 1 2 5 5 5 1
1
1
2
2
4
4
4
5
7
10
The following ways of choosing vertices should be counted:
- when
- when
- when
- when
- when
- when
1
1
If , the -nd line of the Input is empty.
10
1 2 3 4 5 6 7 8 9
1
1
1
1
1
1
1
1
1
1
13
1 1 1 2 2 2 3 3 3 4 4 4
1
1
2
4
4
4
4
4
7
13
13
19
31