from math import gcd

K = int(eval(input()))

res = 0

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

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

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

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

print(res)
import time

def gcd(a, b):

    return a if b == 0 else gcd(b, a%b)



K = int(eval(input()))

res = 0

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

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

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

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

print(res)
from math import gcd

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

import time


def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)


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

-from math import gcd +import time + + +def gcd(a, b): +    return a if b == 0 else gcd(b, a % b) +