from math import gcd

from functools import reduce

def gcd_list(numbers):

   return reduce(gcd, numbers)

k=int(eval(input()))

ans=0

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

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

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

            ans+=gcd_list([i,j,x])

print(ans)
from math import gcd

k=int(eval(input()))

ans=0

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

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

        p=gcd(i,j)

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

            ans+=gcd(x,p)

print(ans)
from math import gcd
from functools import reduce


def gcd_list(numbers):
    return reduce(gcd, numbers)


k = int(eval(input()))
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for x in range(1, k + 1):
            ans += gcd_list([i, j, x])
print(ans)

from math import gcd

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

-from functools import reduce - - -def gcd_list(numbers): -    return reduce(gcd, numbers) - +        p = gcd(i, j) -            ans += gcd_list([i, j, x]) +            ans += gcd(x, p)