AT_abc469_f.GCD Maximum Spanning Tree
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a sequence of positive integers A of length N.
There is a weighted complete undirected graph with N vertices.
The vertices are numbered 1,2,…,N.
For i and j satisfying 1≤i<j≤N, the weight of the edge connecting vertices i and j is the greatest common divisor of Ai and Aj.
Find the maximum possible value of the sum of the weights of the edges included in a spanning tree of this graph.
给你一个长度为 N 的正整数序列 A。
存在一个含 N 个顶点的带权无向完全图。
顶点编号为 1,2,…,N。
对于满足 1≤i<j≤N 的 i 和 j,连接顶点 i 和 j 的边的权重为 Ai 与 Aj 的最大公约数。
求该图的一棵生成树中所含边的权重之和的最大可能值。
输入格式
The input is given from Standard Input in the following format:
N
A1 A2 … AN
输入从标准输入中按以下格式给出:
N
A1 A2 … AN
输出格式
Output the answer in one line.
一行输出答案。
输入输出样例
输入#1
3 4 6 12
输出#1
10
输入#2
5 5 14 15 21 42
输出#2
43
输入#3
2 1 1000000
输出#3
1
说明/提示
Sample 1 Explanation:
The complete graph has the following three edges.
- The edge connecting vertices 1 and 2 with weight 2
- The edge connecting vertices 1 and 3 with weight 4
- The edge connecting vertices 2 and 3 with weight 6
Choosing the second and third edges gives a sum of weights of 10, which is the maximum possible value.
Constraints
- 2≤N≤2×105
- 1≤A1<A2<⋯<AN≤106
- All input values are integers.
样例 1 解释:
该完全图包含以下三条边:
- 连接顶点 1 和 2、权值为 2 的边
- 连接顶点 1 和 3、权值为 4 的边
- 连接顶点 2 和 3、权值为 6 的边
选择第二条和第三条边,可得到权值之和为 10,这是可能的最大值。
限制条件
- 2≤N≤2×105
- 1≤A1<A2<⋯<AN≤106
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?