CodeForces - 1101D:GCD Counting (樹分治)
You are given a tree consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to ai
.
Let's denote the function g(x,y)
as the greatest common divisor of the numbers written on the vertices belonging to the simple path from vertex x to vertex
.
Your task is calculate the maximum value of dist(x,y)