from math import gcd

 

k = int(eval(input()))

sum_ = 0

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

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

    gcd_ab = gcd(a, b)

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

      sum_ += gcd(c, gcd_ab)

print(sum_)
k = int(eval(input()))

n = 3

c = {i: pow(k//i, n) for i in range(1, k+1)}

for i in range(k, 0, -1):

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

        c[i] -= c[j]

_sum = 0

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

    _sum += c[x] * x

print(_sum)

from math import gcd

k = int(eval(input()))
sum_ = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        gcd_ab = gcd(a, b)
        for c in range(1, k + 1):
            sum_ += gcd(c, gcd_ab)
print(sum_)

k = int(eval(input()))
n = 3
c = {i: pow(k // i, n) for i in range(1, k + 1)}
for i in range(k, 0, -1):
    for j in range(2 * i, k + 1, i):
        c[i] -= c[j]
_sum = 0
for x in range(1, k + 1):
    _sum += c[x] * x
print(_sum)

-from math import gcd - -sum_ = 0 -for a in range(1, k + 1): -    for b in range(1, k + 1): -        gcd_ab = gcd(a, b) -        for c in range(1, k + 1): -            sum_ += gcd(c, gcd_ab) -print(sum_) +n = 3 +c = {i: pow(k // i, n) for i in range(1, k + 1)} +for i in range(k, 0, -1): +    for j in range(2 * i, k + 1, i): +        c[i] -= c[j] +_sum = 0 +for x in range(1, k + 1): +    _sum += c[x] * x +print(_sum)