import math

N = int(eval(input()))

all_gcd = []

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

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

    x = math.gcd(i, j) if i != j else i

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

      y = math.gcd(x, m) if x != m else x

      all_gcd.append(y)



print((sum(all_gcd)))

import math

N = int(eval(input()))

all_gcd = [math.gcd(math.gcd(i, j), m) for i in range(1, N+1) for j in range(1, N+1) for m in range(1, N+1)]

print((sum(all_gcd)))

import math

N = int(eval(input()))
all_gcd = []
for i in range(1, N + 1):
    for j in range(1, N + 1):
        x = math.gcd(i, j) if i != j else i
        for m in range(1, N + 1):
            y = math.gcd(x, m) if x != m else x
            all_gcd.append(y)
print((sum(all_gcd)))

import math

N = int(eval(input()))
all_gcd = [
    math.gcd(math.gcd(i, j), m)
    for i in range(1, N + 1)
    for j in range(1, N + 1)
    for m in range(1, N + 1)
]
print((sum(all_gcd)))

-all_gcd = [] -for i in range(1, N + 1): -    for j in range(1, N + 1): -        x = math.gcd(i, j) if i != j else i -        for m in range(1, N + 1): -            y = math.gcd(x, m) if x != m else x -            all_gcd.append(y) +all_gcd = [ +    math.gcd(math.gcd(i, j), m) +    for i in range(1, N + 1) +    for j in range(1, N + 1) +    for m in range(1, N + 1) +]