No.1917 LCMST
タグ : / 解いたユーザー数 87
作問者 :
とりゐ
/ テスター :
riano
Problem Statement
Consider a complete graph $G$ with $N$ vertices. The weight of the edge connecting vertex $i$ and vertex $j$ is the least common multiple of $A_i$ and $A_j$. Find the sum of the weights of the edges contained in a minimum spanning tree of $G$.
Input
$N$ $A_1$ $A_2$ $\ldots$ $A_N$
- $2\leq N\leq 10^6$
- $1\leq A_i\leq 10^5$
- All inputs are integers.
Output
Output the sum of the weights of the edges contained in a minimum spanning tree.
Sample
Sample 1
Input
3 2 3 4
Output
10
Let $\mathrm{lcm}(a,b)$ denote the least common multiple of $a$ and $b$.
By adding an edge of weight $\mathrm{lcm}(2,3)=6$ between vertex $1$ and vertex $2$, and an edge of weight $\mathrm{lcm}(2,4)=4$ between vertex $1$ and vertex $3$, the sum of the edge weights of the spanning tree becomes $10$, which is the minimum.
Sample 2
Input
5 3 1 4 1 5
Output
13
Sample 3
Input
5 593 401 467 241 227
Output
386354
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。