PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000220. Tổng ƯCLN trên mọi bộ ba (Sum of gcd of Tuples (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ổng ƯCLN trên mọi bộ ba (Sum of gcd of Tuples (Easy))
Sum of gcd of Tuples (Easy)
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given a positive integer , consider every ordered triple with . Compute
$$S=\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K}\gcd(a,b,c).$$Different orders count separately. Print the exact answer without a modulus.
Input
One line containing .
Output
Print the integer .
Subtasks
-
Subtask 1 (20 points): .
-
Subtask 2 (30 points): .
-
Subtask 3 (50 points): .
Examples
Example 1
Input
2
Output
9
Explanation
There are eight ordered triples. Seven have GCD 1, while (2,2,2) has GCD 2; hence the total is 7+2=9.
Example 2
Input
1
Output
1
Explanation
The only triple is (1,1,1), whose GCD is 1.
Example 3
Input
200
Output
10813692
Explanation
Use the identity to group the contribution of each divisor instead of enumerating all triples.