from math import gcd



K = int(eval(input()))



ans = 0

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

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

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

            ans += gcd(gcd(a, b), c)



print(ans)
from numba import njit

from math import gcd



K = int(eval(input()))



@njit

def solve():

    ans = 0

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

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

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

                ans += gcd(gcd(a, b), c)

    return ans



print((solve()))
from math import gcd

K = int(eval(input()))
ans = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            ans += gcd(gcd(a, b), c)
print(ans)

from numba import njit
from math import gcd

K = int(eval(input()))


@njit
def solve():
    ans = 0
    for a in range(1, K + 1):
        for b in range(1, K + 1):
            for c in range(1, K + 1):
                ans += gcd(gcd(a, b), c)
    return ans


print((solve()))

+from numba import njit -ans = 0 -for a in range(1, K + 1): -    for b in range(1, K + 1): -        for c in range(1, K + 1): -            ans += gcd(gcd(a, b), c) -print(ans) + + +@njit +def solve(): +    ans = 0 +    for a in range(1, K + 1): +        for b in range(1, K + 1): +            for c in range(1, K + 1): +                ans += gcd(gcd(a, b), c) +    return ans + + +print((solve()))