import itertools

import math



k = int(eval(input()))

x = 0

for v in itertools.combinations_with_replacement(list(range(1, k+1)), 3):

    a, b, c = v

    x = x + math.gcd(math.gcd(a,b), c)



y = 0

for v in itertools.combinations(list(range(1, k+1)), 3):

    a, b, c = v

    y = y + math.gcd(math.gcd(a,b), c)



z = k * (1 + k) / 2

print(( int(3 * x  + y * 3  -  2 * z)))
import math

 

k = int(eval(input()))

 

cache = {}

ans = 0

for a in range(1, k+1):

    for b in range(1, k+1):

        for c in range(1, k+1):

            ans = ans + cache.get( (a,b,c), math.gcd(math.gcd(a, b), c))

print(ans)
import itertools
import math

k = int(eval(input()))
x = 0
for v in itertools.combinations_with_replacement(list(range(1, k + 1)), 3):
    a, b, c = v
    x = x + math.gcd(math.gcd(a, b), c)
y = 0
for v in itertools.combinations(list(range(1, k + 1)), 3):
    a, b, c = v
    y = y + math.gcd(math.gcd(a, b), c)
z = k * (1 + k) / 2
print((int(3 * x + y * 3 - 2 * z)))

import math

k = int(eval(input()))
cache = {}
ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            ans = ans + cache.get((a, b, c), math.gcd(math.gcd(a, b), c))
print(ans)

-import itertools -x = 0 -for v in itertools.combinations_with_replacement(list(range(1, k + 1)), 3): -    a, b, c = v -    x = x + math.gcd(math.gcd(a, b), c) -y = 0 -for v in itertools.combinations(list(range(1, k + 1)), 3): -    a, b, c = v -    y = y + math.gcd(math.gcd(a, b), c) -z = k * (1 + k) / 2 -print((int(3 * x + y * 3 - 2 * z))) +cache = {} +ans = 0 +for a in range(1, k + 1): +    for b in range(1, k + 1): +        for c in range(1, k + 1): +            ans = ans + cache.get((a, b, c), math.gcd(math.gcd(a, b), c)) +print(ans)