from math import gcd

N = int(eval(input()))

ans = 0

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

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

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

      ans += gcd(gcd(i,j),k)



print(ans)

K = int(eval(input()))

total = 0



def gdc(x,y):

  if x%y==0:

    return y

  return gdc(y, x%y)



for a in range(K):

  for b in range(K):

    for c in range(K):

      total += gdc(c+1, gdc(b+1, a+1))

print(total)



from math import gcd

N = int(eval(input()))
ans = 0
for i in range(1, N + 1):
    for j in range(1, N + 1):
        for k in range(1, N + 1):
            ans += gcd(gcd(i, j), k)
print(ans)

K = int(eval(input()))
total = 0


def gdc(x, y):
    if x % y == 0:
        return y
    return gdc(y, x % y)


for a in range(K):
    for b in range(K):
        for c in range(K):
            total += gdc(c + 1, gdc(b + 1, a + 1))
print(total)

-from math import gcd +K = int(eval(input())) +total = 0 -N = int(eval(input())) -ans = 0 -for i in range(1, N + 1): -    for j in range(1, N + 1): -        for k in range(1, N + 1): -            ans += gcd(gcd(i, j), k) -print(ans) + +def gdc(x, y): +    if x % y == 0: +        return y +    return gdc(y, x % y) + + +for a in range(K): +    for b in range(K): +        for c in range(K): +            total += gdc(c + 1, gdc(b + 1, a + 1)) +print(total)