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

Bài tập thuộc lộ trình

1 lộ trình

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 KK, consider every ordered triple (a,b,c)(a,b,c) with 1≤a,b,c≤K1\le a,b,c\le K. 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 KK.

Output

Print the integer SS.

Subtasks

  • Subtask 1 (20 points): 1≤K≤201\le K\le 20.

  • Subtask 2 (30 points): 1≤K≤1001\le K\le 100.

  • Subtask 3 (50 points): 1≤K≤2001\le K\le 200.

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 ∑d∣gφ(d)=g\sum_{d\mid g}\varphi(d)=g to group the contribution of each divisor instead of enumerating all 2003200^3 triples.