import math 

import sys

read_=sys.stdin.buffer.readline



K=int(read_())

ans=0

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

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

        x=math.gcd(a,b)

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

            ans+=math.gcd(x,c)

print(ans)
from math import gcd 

import sys

read=sys.stdin.buffer.readline



K=int(read())

l=[[0]*(K+1) for _ in range(K+1)]

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

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

        x=gcd(i,j)

        l[i][j],l[j][i]=x,x



ans=0

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

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

        x=l[a][b]

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

            ans+=l[x][c]



print(ans)
import math
import sys

read_ = sys.stdin.buffer.readline
K = int(read_())
ans = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        x = math.gcd(a, b)
        for c in range(1, K + 1):
            ans += math.gcd(x, c)
print(ans)

from math import gcd
import sys

read = sys.stdin.buffer.readline
K = int(read())
l = [[0] * (K + 1) for _ in range(K + 1)]
for i in range(1, K + 1):
    for j in range(i, K + 1):
        x = gcd(i, j)
        l[i][j], l[j][i] = x, x
ans = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        x = l[a][b]
        for c in range(1, K + 1):
            ans += l[x][c]
print(ans)

-import math +from math import gcd -read_ = sys.stdin.buffer.readline -K = int(read_()) +read = sys.stdin.buffer.readline +K = int(read()) +l = [[0] * (K + 1) for _ in range(K + 1)] +for i in range(1, K + 1): +    for j in range(i, K + 1): +        x = gcd(i, j) +        l[i][j], l[j][i] = x, x -        x = math.gcd(a, b) +        x = l[a][b] -            ans += math.gcd(x, c) +            ans += l[x][c]