Bob has a tree with nodes, rooted at node
. The nodes are numbered from
to
. Each edge in the tree has a length of
, and for every node
(
), its parent is node
, which satisfies
.
For any two nodes and
, define the function:
Where:
LCA(u, v)
is the lowest common ancestor of nodesand
.
dist(x, y)
is the number of edges in the unique path between nodesand
.
GCD(x, y)
is the greatest common divisor ofand
, with
GCD(0, x) = x
.
Bob wants to compute, for every integer from
to
, the number of unordered pairs
with
such that
. Can you write a program to help Bob?
Input Specification
The first line of input contains one integer (
), the number of nodes.
Each of the following lines contains one integer
(
), indicating the parent node of node
.
Output Specification
Output lines. The
-th line contains one integer, the number of pairs
(
) so that
.
Constraints
For all test cases, .
Subtask | Points | Additional constraints |
---|---|---|
Each node has at most one child, except for the root node. | ||
No additional constraints. |
Sample Input 1
5
1
2
2
1
Sample Output 1
8
2
0
0
Explanation for Sample 1
- There are
pairs of
with
:
,
,
,
,
,
,
,
.
- There are
pairs of
with
:
and
.
Sample Input 2
8
1
2
3
4
1
6
6
Sample Output 2
16
9
2
1
0
0
0
Comments