시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2.5 초 | 1024 MB | 135 | 36 | 25 | 23.364% |
You are given an undirected tree with $N$ vertices, labeled with distinct integers from $1$ to $N$.
Let's denote $\textrm {dist}(i,\, j)$ be the length of the shortest path between two vertices $i$ and $j$ on the tree.
Find $\sum_{1 \leq i < j \leq N} \gcd(i,\, j,\, \textrm {dist}(i,\, j))$.
$\gcd(a, b, c)$ means the greatest common divisor of $a$, $b$, and $c$.
The first line contains an integer $N$.
Each of the following $N-1$ lines contains two space-separated integers $u_i$ and $v_i$ $(1 \le i \le N-1)$, which means that there is an edge between them.
Print the value of $ \Sigma_{1 \leq i < j \leq N} \gcd(i,\ j,\ dist(i, j)) $.
This subtask has an additional constraint:
This subtask has an additional constraint:
This subtask has no additional constraints.
3 1 2 1 3
3
4 1 2 1 3 1 4
7
6 1 3 1 5 5 2 6 5 5 4
20