import math

from functools import reduce



def gcd(*numbers):

    return reduce(math.gcd, numbers)

K=int(eval(input()))

ans=[]

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

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

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

            ans.append(gcd(i,j,k))

print((sum(ans)))   
import math

from functools import reduce



def gcd(*numbers):

    return reduce(math.gcd, numbers)

K=int(eval(input()))

ans=0

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

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

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

            ans+=gcd(i,j,k)

print(ans)
import math
from functools import reduce


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


K = int(eval(input()))
ans = []
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            ans.append(gcd(i, j, k))
print((sum(ans)))

import math
from functools import reduce


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


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

-ans = [] +ans = 0 -            ans.append(gcd(i, j, k)) -print((sum(ans))) +            ans += gcd(i, j, k) +print(ans)