import math

K = int(eval(input()))

ans = 0

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

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

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

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

print(ans)           



import math

# K = int(input())

# ans = 0

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

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

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

#             ans+=math.gcd(i,math.gcd(j,k)) 

# print(ans)           





ans = 0

K = int(eval(input()))

dp = [[1] * 220 for i in range(220)] 

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

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

        dp[i][j] = math.gcd(i,j)

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

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

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

            a = dp[i][j]

            ans += dp[a][k]

print(ans)

import math

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

import math

# K = int(input())
# ans = 0
# for i in range(1,K+1):
#     for j in range(1,K+1):
#         for k in range(1,K+1):
#             ans+=math.gcd(i,math.gcd(j,k))
# print(ans)
ans = 0
K = int(eval(input()))
dp = [[1] * 220 for i in range(220)]
for i in range(1, K + 1):
    for j in range(1, K + 1):
        dp[i][j] = math.gcd(i, j)
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            a = dp[i][j]
            ans += dp[a][k]
print(ans)

+# K = int(input()) +# ans = 0 +# for i in range(1,K+1): +#     for j in range(1,K+1): +#         for k in range(1,K+1): +#             ans+=math.gcd(i,math.gcd(j,k)) +# print(ans) +ans = 0 -ans = 0 +dp = [[1] * 220 for i in range(220)] +for i in range(1, K + 1): +    for j in range(1, K + 1): +        dp[i][j] = math.gcd(i, j) -            ans += math.gcd(i, math.gcd(j, k)) +            a = dp[i][j] +            ans += dp[a][k]