import math

from numba import jit



K = int(eval(input()))





@jit

def apt(N):

    cnt = 0

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

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

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

                cnt += math.gcd(k, math.gcd(i, j))

    return cnt





print((apt(K)))

import math



K = int(eval(input()))

cnt = 0

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

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

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

            cnt += math.gcd(k, math.gcd(i, j))





print(cnt)

import math
from numba import jit

K = int(eval(input()))


@jit
def apt(N):
    cnt = 0
    for i in range(1, K + 1):
        for j in range(1, K + 1):
            for k in range(1, K + 1):
                cnt += math.gcd(k, math.gcd(i, j))
    return cnt


print((apt(K)))

import math

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

-from numba import jit - - -@jit -def apt(N): -    cnt = 0 -    for i in range(1, K + 1): -        for j in range(1, K + 1): -            for k in range(1, K + 1): -                cnt += math.gcd(k, math.gcd(i, j)) -    return cnt - - -print((apt(K))) +cnt = 0 +for i in range(1, K + 1): +    for j in range(1, K + 1): +        for k in range(1, K + 1): +            cnt += math.gcd(k, math.gcd(i, j)) +print(cnt)