#P6786. 「SWTR-6」GCD & LCM
「SWTR-6」GCD & LCM
Problem Description
Little A has a sequence of length : .
He wants to choose some numbers from these numbers such that: for all , is either the maximum value in sequence , or there exists a position such that and .
- If you do not know what and are, you can click the link in the "Help / Hint" section at the bottom.
Little A wants the sum of the chosen numbers to be as large as possible. Please output this maximum value.
Input Format
The first line contains an integer , representing the length of the sequence.
The second line contains integers .
Output Format
Output one line with one integer, representing the answer.
4
4 3 2 1
5
10
6 7 18 4 17 10 9 1 3 8
19
3
123456789 234567890 123456789
246913578
Hint
"Sample 1 Explanation"
You can choose , because .
"Constraints and Notes"
This problem uses bundled testdata.
- Subtask 1 (5 points): .
- Subtask 2 (20 points): .
- Subtask 3 (15 points): .
- Subtask 4 (15 points): .
- Subtask 5 (10 points): .
- Subtask 6 (10 points): .
- Subtask 7 (25 points): no special constraints.
For of the testdata, , .
"Help / Hint"
means greatest common divisor, and means least common multiple.
"Source"
【LGR-075】Luogu August Monthly Contest II Div.2 & SWTR-06 & EZEC Round 3.
idea & solution & data by Alex_Wei.
Translated by ChatGPT 5