GCD on a tree

5

5 votes
Problem

You are given a tree with n nodes. The nodes are numbered from 1 to n. Let us define the gcd of a path as the greatest common divisor of all values of the nodes in the path. Let denote the number of simple paths on the tree whose gcd is g. Formally, equals the number of sequences , such that and are connected by an edge for all , and for , and .

Find the values of for all

Input
The first line contains n, the number of nodes in the tree.
Each of the next lines contain 2 integers , denoting node u, and node v are connected by an edge.

Output
Print a single line containing n integers. The integer equals .

Constraints

Sample Input
4
1 2
2 3
2 4
Sample Output
11 3 1 1 
Time Limit: 6
Memory Limit: 256
Source Limit:
Explanation

The path from 2 to 4, and the path from 4 to 2, has gcd value 2. All other paths with more than 1 nodes have gcd 1. The path i to i has gcd i

Contributers:
Editor Image

?