問題一覧 > 通常問題

No.1917 LCMST

レベル : / AI推定難易度 : 2300 / 実行時間制限 : 1ケース 4.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 87
作問者 : とりゐ / テスター : chineristAC riano
お気に入りにしたユーザー ProblemId : 7820 / 自分の提出
問題文最終更新日: 2022-06-24 23:43:47
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 341 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。