QOJ.ac

QOJ

Límite de tiempo: 3 s Límite de memoria: 1024 MB Puntuación total: 100

#6463. 游客

Estadísticas

在树城(Tree City)中,有 $n$ 个旅游景点,编号唯一,从 $1$ 到 $n$。这些景点由 $n-1$ 条双向道路连接,使得游客可以通过某条道路路径从任意一个景点到达另一个景点。

你是树城规划委员会的一员。经过对旅游业的大量研究,委员会发现了一个关于游客的非常有趣的现象:他们热爱数论!如果一名游客访问了编号为 $x$ 的景点,那么他接下来会访问编号为 $y$ 的景点,前提是 $y > x$ 且 $y$ 是 $x$ 的倍数。此外,如果这两个景点之间没有直接的道路相连,游客必然会访问连接 $x$ 和 $y$ 的路径上的所有景点,即使这些景点不是 $x$ 的倍数。所访问的景点数量包括 $x$ 和 $y$ 本身。我们将此称为路径的长度。

考虑以下城市地图:

以下是游客可能采取的所有路径及其对应的长度: $1 \to 2 = 4, 1 \to 3 = 3, 1 \to 4 = 2, 1 \to 5 = 2, 1 \to 6 = 3, 1 \to 7 = 4,$ $1 \to 8 = 3, 1 \to 9 = 3, 1 \to 10 = 2, 2 \to 4 = 5, 2 \to 6 = 6, 2 \to 8 = 2,$ $2 \to 10 = 3, 3 \to 6 = 3, 3 \to 9 = 3, 4 \to 8 = 4, 5 \to 10 = 3$

为了利用这种游客行为现象,委员会希望确定所有满足 $y > x$ 且 $y$ 是 $x$ 的倍数的景点 $x$ 到景点 $y$ 的路径上的景点数量。你需要计算所有此类路径长度的总和。对于上面的例子,总和为:$4 + 3 + 2 + 2 + 3 + 4 + 3 + 3 + 2 + 5 + 6 + 2 + 3 + 3 + 3 + 4 + 3 = 55$。

输入格式

输入包含单个测试用例。注意,你的程序可能会在不同的输入上多次运行。输入的第一行包含一个整数 $n$ ($2 \le n \le 200,000$),表示景点的数量。接下来的 $n-1$ 行,每行包含一对以空格分隔的整数 $i$ 和 $j$ ($1 \le i < j \le n$),表示景点 $i$ 和景点 $j$ 之间有直接的道路相连。保证景点集合是连通的。

输出格式

输出一个整数,即所有满足 $y > x$ 且 $y$ 是 $x$ 的倍数的景点 $x$ 到景点 $y$ 的路径长度之和。

样例

样例输入 1

10
3 4
3 7
1 4
4 6
1 10
8 10
2 8
1 5
4 9

样例输出 1

55

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.