import math

K =int(eval(input()))

L = [0 for _ in range(K)]

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

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

    L[math.gcd(a,b)-1] +=1

s = 0

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

    for k in range(K):

        for _ in range(L[k]):

            s += math.gcd(c,k+1)

print(s)
import math

K = int(eval(input()))

s = 0

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

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

    x = math.gcd(a,b)

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

      s += math.gcd(x,c)

print(s)

import math

K = int(eval(input()))
L = [0 for _ in range(K)]
for a in range(1, K + 1):
    for b in range(1, K + 1):
        L[math.gcd(a, b) - 1] += 1
s = 0
for c in range(1, K + 1):
    for k in range(K):
        for _ in range(L[k]):
            s += math.gcd(c, k + 1)
print(s)

import math

K = int(eval(input()))
s = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        x = math.gcd(a, b)
        for c in range(1, K + 1):
            s += math.gcd(x, c)
print(s)

-L = [0 for _ in range(K)] +s = 0 -        L[math.gcd(a, b) - 1] += 1 -s = 0 -for c in range(1, K + 1): -    for k in range(K): -        for _ in range(L[k]): -            s += math.gcd(c, k + 1) +        x = math.gcd(a, b) +        for c in range(1, K + 1): +            s += math.gcd(x, c)