import math

k = int(eval(input()))



ans = 0

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

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

      m = math.gcd(a, b)

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

          ans += math.gcd(m, c)



print(ans)

K = int(eval(input()))

from math import gcd



sum_gcd = [0]*K

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

    c = 0

    for j in range(1,K+1):

        c += gcd(i,j)

    sum_gcd[i-1] = c

ans = 0

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

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

        ans += sum_gcd[gcd(a,b)-1]



print(ans)
import math

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

K = int(eval(input()))
from math import gcd

sum_gcd = [0] * K
for i in range(1, K + 1):
    c = 0
    for j in range(1, K + 1):
        c += gcd(i, j)
    sum_gcd[i - 1] = c
ans = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        ans += sum_gcd[gcd(a, b) - 1]
print(ans)

-import math +K = int(eval(input())) +from math import gcd -k = int(eval(input())) +sum_gcd = [0] * K +for i in range(1, K + 1): +    c = 0 +    for j in range(1, K + 1): +        c += gcd(i, j) +    sum_gcd[i - 1] = c -for a in range(1, k + 1): -    for b in range(1, k + 1): -        m = math.gcd(a, b) -        for c in range(1, k + 1): -            ans += math.gcd(m, c) +for a in range(1, K + 1): +    for b in range(1, K + 1): +        ans += sum_gcd[gcd(a, b) - 1]