PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000237. Tổng ƯCLN của hai số nhỏ nhất (Small 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 của hai số nhỏ nhất (Small GCD)
Tổng ƯCLN của hai số nhỏ nhất (Small GCD)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
For each triple of distinct indices , sort the three values, take the GCD of the two smallest, and sum over all triples. No modulus is applied.
Input
- First line: integer .
- Second line: array elements.
Output
Print the exact sum without a modulus.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
5
2 3 6 12 17
Output
24
Explanation
Summing the GCD of the two smallest numbers over all ten triples gives 24.
Example 2
Input
3
2 4 8
Output
2
Explanation
The only triple has two smallest values 2 and 4, whose GCD is 2.