import math

K=int(eval(input()))

tot=0

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

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

        tmp=math.gcd(i,j)

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

            tot+=math.gcd(tmp,k)

print(tot)
# https://atcoder.jp/contests/abc162/tasks/abc162_c

import math

K=int(eval(input()))

# K=200

tot=0

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

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

#         tmp=math.gcd(i,j)

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

#             tot+=math.gcd(tmp,k)

ls=[0]*202

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

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

        tmp=math.gcd(i,j)

        ls[tmp+1]+=1

tot=0

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

    for j in range(1,201):

        tot+=ls[j+1]*math.gcd(j,i)



print(tot)
import math

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

# https://atcoder.jp/contests/abc162/tasks/abc162_c
import math

K = int(eval(input()))
# K=200
tot = 0
# for i in range(1,K+1):
#     for j in range(1,K+1):
#         tmp=math.gcd(i,j)
#         for k in range(1,K+1):
#             tot+=math.gcd(tmp,k)
ls = [0] * 202
for i in range(1, K + 1):
    for j in range(1, K + 1):
        tmp = math.gcd(i, j)
        ls[tmp + 1] += 1
tot = 0
for i in range(1, K + 1):
    for j in range(1, 201):
        tot += ls[j + 1] * math.gcd(j, i)
print(tot)

+# https://atcoder.jp/contests/abc162/tasks/abc162_c +# K=200 +# for i in range(1,K+1): +#     for j in range(1,K+1): +#         tmp=math.gcd(i,j) +#         for k in range(1,K+1): +#             tot+=math.gcd(tmp,k) +ls = [0] * 202 -        for k in range(1, K + 1): -            tot += math.gcd(tmp, k) +        ls[tmp + 1] += 1 +tot = 0 +for i in range(1, K + 1): +    for j in range(1, 201): +        tot += ls[j + 1] * math.gcd(j, i)