import math



K=int(eval(input()))

ans=0

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

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

        a = math.gcd(i,j)

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

            b = math.gcd(a,k)

            ans += b



print(ans) 
import math



K=int(eval(input()))

ans=0

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

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

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

            a = math.gcd(i,j)

            b = math.gcd(a,k)

            ans += b



print(ans) 
import math

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

import math

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

-        a = math.gcd(i, j) +            a = math.gcd(i, j)