import math

K = int(eval(input()))

sumval = 0

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

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

        f = math.gcd(a,b)

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

            g = math.gcd(f,c)

            sumval += g

print(sumval)
import math

K = int(eval(input()))

sumval = 0

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

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

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

            f = math.gcd(a,b)

            g = math.gcd(f,c)

            sumval += g

print(sumval)
import math

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

import math

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

-        f = math.gcd(a, b) +            f = math.gcd(a, b)