import math

from functools import reduce



def gcd(*numbers):

    return reduce(math.gcd, numbers)



ans=0

K=int(eval(input()))

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

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

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

      ans+=gcd(a,b,c)

print(ans)

k = int(eval(input()))



from math import gcd



#gcd_sum = [0] * 201

ans = 0



'''

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

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

        gcd_sum[i] += gcd(i,j)

        #print(gcd(i,j))

        #print(gcd_sum[i])

'''

       

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

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

        g = gcd(a,b)

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

            ans += gcd(g,c)

        #print(g)

        #print(ans)



print(ans)
import math
from functools import reduce


def gcd(*numbers):
    return reduce(math.gcd, numbers)


ans = 0
K = int(eval(input()))
for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            ans += gcd(a, b, c)
print(ans)

k = int(eval(input()))
from math import gcd

# gcd_sum = [0] * 201
ans = 0
"""
for i in range(1, k+1):
    for j in range(1, k+1):
        gcd_sum[i] += gcd(i,j)
        #print(gcd(i,j))
        #print(gcd_sum[i])
"""
for a in range(1, k + 1):
    for b in range(1, k + 1):
        g = gcd(a, b)
        for c in range(1, k + 1):
            ans += gcd(g, c)
        # print(g)
        # print(ans)
print(ans)

-import math -from functools import reduce +k = int(eval(input())) +from math import gcd - -def gcd(*numbers): -    return reduce(math.gcd, numbers) - - +# gcd_sum = [0] * 201 -K = int(eval(input())) -for a in range(1, K + 1): -    for b in range(1, K + 1): -        for c in range(1, K + 1): -            ans += gcd(a, b, c) +""" +for i in range(1, k+1): +    for j in range(1, k+1): +        gcd_sum[i] += gcd(i,j) +        #print(gcd(i,j)) +        #print(gcd_sum[i]) +""" +for a in range(1, k + 1): +    for b in range(1, k + 1): +        g = gcd(a, b) +        for c in range(1, k + 1): +            ans += gcd(g, c) +        # print(g) +        # print(ans)