import math

K = int(eval(input()))

ans = 0

result = 0

dp = [[[0 for i in range(K+1)] for i in range(K+1)]for i in range(K+1)]

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

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

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

            if dp[i][j][k] == 0:

                x = math.gcd(i,j)

                y = math.gcd(j,k)

                ans = math.gcd(x,y)

                dp[i][j][k] = ans

                dp[j][i][k] = ans

                dp[k][i][j] = ans

                dp[k][j][i] = ans

                result += ans

            else:

                result += max(dp[i][j][k],dp[j][i][k],dp[k][i][j],dp[k][j][i])

print(result)
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):

            x = math.gcd(i,j)

            y = math.gcd(j,k)

            ans += math.gcd(x,y)

print(ans)
import math

K = int(eval(input()))
ans = 0
result = 0
dp = [[[0 for i in range(K + 1)] for i in range(K + 1)] for i in range(K + 1)]
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            if dp[i][j][k] == 0:
                x = math.gcd(i, j)
                y = math.gcd(j, k)
                ans = math.gcd(x, y)
                dp[i][j][k] = ans
                dp[j][i][k] = ans
                dp[k][i][j] = ans
                dp[k][j][i] = ans
                result += ans
            else:
                result += max(dp[i][j][k], dp[j][i][k], dp[k][i][j], dp[k][j][i])
print(result)

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):
            x = math.gcd(i, j)
            y = math.gcd(j, k)
            ans += math.gcd(x, y)
print(ans)

-result = 0 -dp = [[[0 for i in range(K + 1)] for i in range(K + 1)] for i in range(K + 1)] -            if dp[i][j][k] == 0: -                x = math.gcd(i, j) -                y = math.gcd(j, k) -                ans = math.gcd(x, y) -                dp[i][j][k] = ans -                dp[j][i][k] = ans -                dp[k][i][j] = ans -                dp[k][j][i] = ans -                result += ans -            else: -                result += max(dp[i][j][k], dp[j][i][k], dp[k][i][j], dp[k][j][i]) -print(result) +            x = math.gcd(i, j) +            y = math.gcd(j, k) +            ans += math.gcd(x, y) +print(ans)