AT_abc469_f.GCD Maximum Spanning Tree

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a sequence of positive integers AA of length NN.
There is a weighted complete undirected graph with NN vertices.
The vertices are numbered 1,2,…,N1,2,\dots,N.
For ii and jj satisfying 1≤i<j≤N1 \leq i \lt j \leq N, the weight of the edge connecting vertices ii and jj is the greatest common divisor of AiA_i and AjA_j.
Find the maximum possible value of the sum of the weights of the edges included in a spanning tree of this graph.

给你一个长度为 NN 的正整数序列 AA。
存在一个含 NN 个顶点的带权无向完全图。
顶点编号为 1,2,…,N1,2,\dots,N。
对于满足 1≤i<j≤N1 \leq i \lt j \leq N 的 ii 和 jj,连接顶点 ii 和 jj 的边的权重为 AiA_i 与 AjA_j 的最大公约数。
求该图的一棵生成树中所含边的权重之和的最大可能值。

输入格式

The input is given from Standard Input in the following format:

NN
A1A_1 A2A_2 …\dots ANA_N

输入从标准输入中按以下格式给出:

NN
A1A_1 A2A_2 …\dots ANA_N

输出格式

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 11 and 22 with weight 22
  • The edge connecting vertices 11 and 33 with weight 44
  • The edge connecting vertices 22 and 33 with weight 66

Choosing the second and third edges gives a sum of weights of 1010, which is the maximum possible value.

Constraints

  • 2≤N≤2×1052 \leq N \leq 2 \times 10^5
  • 1≤A1<A2<⋯<AN≤1061 \leq A_1 \lt A_2 \lt \dots \lt A_N \leq 10^6
  • All input values are integers.

样例 1 解释:
该完全图包含以下三条边:

  • 连接顶点 11 和 22、权值为 22 的边
  • 连接顶点 11 和 33、权值为 44 的边
  • 连接顶点 22 和 33、权值为 66 的边

选择第二条和第三条边,可得到权值之和为 1010,这是可能的最大值。

限制条件

  • 2≤N≤2×1052 \leq N \leq 2 \times 10^5
  • 1≤A1<A2<⋯<AN≤1061 \leq A_1 \lt A_2 \lt \dots \lt A_N \leq 10^6
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页