#P17011. [GESP202606 五级] 晚宴

    ID: 19301 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及− 上传者: 标签>数学枚举最大公约数 gcd2026GESP

[GESP202606 五级] 晚宴

Problem Description

Xiaoming goes to a banquet. There are nn dishes at the banquet, and each dish has a tastiness value. The tastiness of the ii-th dish is viv_i.

The banquet rules say that Xiaoming can select exactly two dishes, and the tastiness values of these two dishes must be coprime (i.e., their greatest common divisor is 11).

Please help Xiaoming choose two dishes so that the sum of their tastiness values is as large as possible.

Input Format

The input has 22 lines.

The first line contains a positive integer nn, representing the number of dishes.

The second line contains nn integers v1,v2,,vnv_1, v_2, \cdots, v_n, representing the tastiness values of the dishes. The integers are separated by spaces.

Output Format

Output one integer, representing the maximum possible sum of tastiness values of two coprime dishes.

5
3 5 7 35 105
38

Hint

Sample Explanation 1

The best choice is 33 and 3535.

Note that the greatest common divisor of 105105 and any other dish is greater than 11, so it cannot be part of a valid choice.

Constraints

2n10002 \le n \le 1000, 1vi10000001 \le v_i \le 1000000.

The testdata guarantees that there are no dishes with the same tastiness value.

The testdata guarantees that there is at least one way to select two dishes.

Translated by ChatGPT 5