0% found this document useful (0 votes)
74 views2 pages

Rty6Ryrtyy. GCJKJKJKJLKJLJKLD Counting: Input

The document describes a problem involving finding the maximum distance between vertices in a tree where the greatest common divisor (GCD) of the numbers on the vertices along the path is greater than 1. It provides details on the input which includes the number of vertices and numbers assigned to each vertex, and edges connecting vertices to form a tree. It also describes the output, which is the maximum distance between such vertices or 0 if no pair satisfies the GCD condition. Sample inputs and outputs are given as examples.

Uploaded by

Samin Afnan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views2 pages

Rty6Ryrtyy. GCJKJKJKJLKJLJKLD Counting: Input

The document describes a problem involving finding the maximum distance between vertices in a tree where the greatest common divisor (GCD) of the numbers on the vertices along the path is greater than 1. It provides details on the input which includes the number of vertices and numbers assigned to each vertex, and edges connecting vertices to form a tree. It also describes the output, which is the maximum distance between such vertices or 0 if no pair satisfies the GCD condition. Sample inputs and outputs are given as examples.

Uploaded by

Samin Afnan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Rty6ryrtyy.

GCjkjkjkjlkjljklD Counting
time limit per test
4.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Input
The first line contains one integer nn — the number of vertices (1≤n≤2⋅105)(1≤n≤2⋅105).
The second line contains nn integers a1a1, a2a2, ..., anan (1≤ai≤2⋅105)(1≤ai≤2⋅105) — the numbers
written on vertices.

e given a tree consisting of nn vertices. A number is written on each vertex; the number on
vertex ii is equal to aiai.

Let's denote the function g(x,y)g(x,y) as the greatest common divisor of the numbers written on the
vertices belonging to the simple path from vertex xx to vertex yy (including these two vertices). Also
let's denote dist(x,y)dist(x,y) as the number of vertices on the simple path between
vertices xx and yy, including the endpoints. dist(x,x)=1dist(x,x)=1 for every vertex xx.
Your task is calculate the maximum value of dist(x,y)dist(x,y) among such pairs of vertices
that g(x,y)>1g(x,y)>1.

ty. GCD Counting


time limit per test
4.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Input
The first line contains one integer nn — the number of vertices (1≤n≤2⋅105)(1≤n≤2⋅105).
The second line contains nn integers a1a1, a2a2, ..., anan (1≤ai≤2⋅105)(1≤ai≤2⋅105) — the numbers
written on vertices.
Then n−1n−1 lines follow, each containing two
integers xx and yy (1≤x,y≤n,x≠y)(1≤x,y≤n,x≠y) denoting an edge connecting vertex xx with
vertex yy. It is guaranteed that these edges form a tree.
Output
If there is no pair of vertices x,yx,y such that g(x,y)>1g(x,y)>1, print 00. Otherwise print the
maximum value of dist(x,y)dist(x,y) among such pairs.

Examples
input
Copy
3
2 3 4
1 2
2 3
output
Copy
1

input
Copy
3
2 3 4
1 3
2 3
output
Copy
2

input
Copy
3
1 1 1
1 2
2 3
output
Copy
0

You might also like