PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000140. Tổng ƯCLN tiền tố (Prefix GCD)
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ổng ƯCLN tiền tố (Prefix GCD)
Prefix GCD
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given positive integers , you may rearrange them in any order, without adding or deleting elements.
For a chosen order, let be the GCD of the first elements. Define
Find the minimum possible value of over all permutations of the array.
Input
The first line contains ; the second contains positive integers .
Output
Print the minimum sum of prefix GCD values.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
3
10 15 6
Output
9
Explanation
Ordering the elements as gives prefix GCDs , , and , for a total of . No permutation achieves a smaller sum.