from math import gcd

k = int(eval(input()))

double = [gcd(i, j) for i in range(1, k+1) for j in range(1, k+1)]

triple = [gcd(i, j) for i in range(1, k+1) for j in double]

print((sum(triple)))

k = int(eval(input()))

d = [0]*(k+1)

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

    d[i] = pow(k//i, 3)



for i in reversed(list(range(1, k+1))):

    for j in range(2*i, k+1, i):

        d[i] -= d[j]



ans = 0

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

    ans += i*d[i]

print(ans)



from math import gcd

k = int(eval(input()))
double = [gcd(i, j) for i in range(1, k + 1) for j in range(1, k + 1)]
triple = [gcd(i, j) for i in range(1, k + 1) for j in double]
print((sum(triple)))

k = int(eval(input()))
d = [0] * (k + 1)
for i in range(1, k + 1):
    d[i] = pow(k // i, 3)
for i in reversed(list(range(1, k + 1))):
    for j in range(2 * i, k + 1, i):
        d[i] -= d[j]
ans = 0
for i in range(1, k + 1):
    ans += i * d[i]
print(ans)

-from math import gcd - -double = [gcd(i, j) for i in range(1, k + 1) for j in range(1, k + 1)] -triple = [gcd(i, j) for i in range(1, k + 1) for j in double] -print((sum(triple))) +d = [0] * (k + 1) +for i in range(1, k + 1): +    d[i] = pow(k // i, 3) +for i in reversed(list(range(1, k + 1))): +    for j in range(2 * i, k + 1, i): +        d[i] -= d[j] +ans = 0 +for i in range(1, k + 1): +    ans += i * d[i] +print(ans)