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()))



count = [pow(k // max(i, 1), 3) for i in range(k + 1)]



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

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

    count[i] -= count[j]



sum_ = 0

for i in range(k + 1):

  sum_ += i * count[i]



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()))
count = [pow(k // max(i, 1), 3) for i in range(k + 1)]
for i in range(k, 0, -1):
    for j in range(2 * i, k + 1, i):
        count[i] -= count[j]
sum_ = 0
for i in range(k + 1):
    sum_ += i * count[i]
print(sum_)

-from math import gcd - +count = [pow(k // max(i, 1), 3) for i in range(k + 1)] +for i in range(k, 0, -1): +    for j in range(2 * i, k + 1, i): +        count[i] -= count[j] -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) +for i in range(k + 1): +    sum_ += i * count[i]