PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000252. Tổng ước chung lớn nhất của các cặp (GCD - Extreme (II))
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 ước chung lớn nhất của các cặp (GCD - Extreme (II))
GCD - Extrem
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a positive integer . Consider every pair of integers satisfying . For each pair, compute , the greatest positive integer dividing both values.
Find the sum of these greatest common divisors over all pairs. Each pair of distinct values is counted exactly once, with the smaller value written first:
For example, when , the six pairs are , , , , , and . Their contributions sum to .
Input
- A single line containing the integer , defining the set of integers from through to consider.
Output
- Print one integer: . The answer is guaranteed to fit in a signed 64-bit integer.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
10
Output
67
Explanation
Fix the larger number and sum over all . For , the individual sums are .
Thus, . No pair is counted twice because .
Example 2
Input
4
Output
7
Explanation
The valid pairs are , , , , , and . Their greatest common divisors are , respectively. Their sum is .