def gcd(a,b):

    while b:

        a,b=b,a%b

    return a

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

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)
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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
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)

-def gcd(a, b): -    while b: -        a, b = b, a % b -    return a - - +from math import gcd