#P1101D. GCD Counting
GCD Counting
Description
You are given a tree consisting of vertices. A number is written on each vertex; the number on vertex is equal to .
Let's denote the function as the greatest common divisor of the numbers written on the vertices belonging to the simple path from vertex to vertex (including these two vertices). Also let's denote as the number of vertices on the simple path between vertices and , including the endpoints. for every vertex .
Your task is calculate the maximum value of among such pairs of vertices that .
The first line contains one integer — the number of vertices .
The second line contains integers , , ..., — the numbers written on vertices.
Then lines follow, each containing two integers and denoting an edge connecting vertex with vertex . It is guaranteed that these edges form a tree.
If there is no pair of vertices such that , print . Otherwise print the maximum value of among such pairs.
Input
The first line contains one integer — the number of vertices .
The second line contains integers , , ..., — the numbers written on vertices.
Then lines follow, each containing two integers and denoting an edge connecting vertex with vertex . It is guaranteed that these edges form a tree.
Output
If there is no pair of vertices such that , print . Otherwise print the maximum value of among such pairs.