import math

k=int(eval(input()))

total=0

info=[0]

for i in range(1,201):

    for j in range(1,201):

        if j<i:

            info.append(0)

            continue

        info.append(math.gcd(i,j))

        #print(str(i)+" "+str(j)+" "+str(math.gcd(i,j)))

#print(info[202])

#print(info)

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

    a=[]

    a.append(i)

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

        a.append(j)

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

            a.append(m)

            a=sorted(a)

            gcd=info[(a[0]-1)*200+a[1]]

            b=min(gcd,a[2])

            c=max(gcd,a[2])

            gcd=info[(b-1)*200+c]

            total+=gcd

            #print(gcd)

            #print(a)

            a=[i,j]

        a=[i]

print(total)
from math import gcd

k=int(eval(input()))

total=0

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

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

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

            g=gcd(i,j)

            g=gcd(g,m)

            total+=g

print(total)
import math

k = int(eval(input()))
total = 0
info = [0]
for i in range(1, 201):
    for j in range(1, 201):
        if j < i:
            info.append(0)
            continue
        info.append(math.gcd(i, j))
        # print(str(i)+" "+str(j)+" "+str(math.gcd(i,j)))
# print(info[202])
# print(info)
for i in range(1, k + 1):
    a = []
    a.append(i)
    for j in range(1, k + 1):
        a.append(j)
        for m in range(1, k + 1):
            a.append(m)
            a = sorted(a)
            gcd = info[(a[0] - 1) * 200 + a[1]]
            b = min(gcd, a[2])
            c = max(gcd, a[2])
            gcd = info[(b - 1) * 200 + c]
            total += gcd
            # print(gcd)
            # print(a)
            a = [i, j]
        a = [i]
print(total)

from math import gcd

k = int(eval(input()))
total = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for m in range(1, k + 1):
            g = gcd(i, j)
            g = gcd(g, m)
            total += g
print(total)

-import math +from math import gcd -info = [0] -for i in range(1, 201): -    for j in range(1, 201): -        if j < i: -            info.append(0) -            continue -        info.append(math.gcd(i, j)) -        # print(str(i)+" "+str(j)+" "+str(math.gcd(i,j))) -# print(info[202]) -# print(info) -    a = [] -    a.append(i) -        a.append(j) -            a.append(m) -            a = sorted(a) -            gcd = info[(a[0] - 1) * 200 + a[1]] -            b = min(gcd, a[2]) -            c = max(gcd, a[2]) -            gcd = info[(b - 1) * 200 + c] -            total += gcd -            # print(gcd) -            # print(a) -            a = [i, j] -        a = [i] +            g = gcd(i, j) +            g = gcd(g, m) +            total += g