Tree GCD

아직 제출이 없습니다시간 제한2.5초메모리 제한1024 MB

문제

You are given an undirected tree with NN vertices, labeled with distinct integers from 11 to NN

Let's denote dist(i,,j)\textrm {dist}(i,\\, j) be the length of the shortest path between two vertices ii and jj on the tree.

Find _1i<jNgcd(i,,j,,dist(i,,j))\sum\_{1 \leq i < j \leq N} \gcd(i,\\, j,\\, \textrm {dist}(i,\\, j))
gcd(a,b,c)\gcd(a, b, c) means the greatest common divisor of aa, bb, and cc.

입력

The first line contains an integer NN.

Each of the following N1N-1 lines contains two space-separated integers u_iu\_i and v_iv\_i (1iN1)(1 \le i \le N-1), which means that there is an edge between them.

출력

Print the value of Σ_1i<jNgcd(i, j, dist(i,j))\Sigma\_{1 \leq i < j \leq N} \gcd(i,\ j,\ dist(i, j)).

제한

  • 3N100,0003 \leq N \leq 100\\,000
  • 1u_iN1 \leq u\_i \leq N (1iN1)(1 \le i \le N-1)
  • 1v_iN1 \leq v\_i \leq N (1iN1)(1 \le i \le N-1)
  • The given graph is a tree