PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000364. Tối đa hóa tổng GCD tiền tố – Bản dễ (Divan and Kostomuksha (Easy))
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tối đa hóa tổng GCD tiền tố – Bản dễ (Divan and Kostomuksha (Easy))
Divan and Kostomuksha (Easy)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of positive integers. You may reorder its elements arbitrarily, but must use every element.
For the chosen order let
Find the maximum possible value of over all permutations. Equal-valued elements at different positions are still separate elements. This is the easy version, with .
Input
- Line 1: .
- Line 2: positive integers .
Output
One integer: the maximum prefix-GCD sum. The answer may exceed 32-bit signed integer range.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
6
2 3 1 2 6 2
Output
14
Explanation
The order [6,2,2,2,3,1] yields prefix gcd values 6,2,2,2,1,1; sum 14.
Example 2
Input
10
5 7 10 3 1 10 100 3 42 54
Output
131
Explanation
The order [100,10,10,5,1,3,3,7,42,54] gives prefix gcd values 100,10,10,5,1,1,1,1,1,1: total 131.