n = int(eval(input()))



def gcd(a,b):

    while b:

        a, b = b, a % b

    return a



ans = 0

if n == 1:

    ans = 1

else:

    for i in range(n):

        i = i + 1

        for j in range(n):

            j = j + 1

            for k in range(n):

                k = k + 1

                ij = gcd(i,j)

                ans = ans + gcd(ij,k)



print(ans)

import math

n = int(eval(input()))



ans = 0

if n == 1:

    ans = 1

else:

    for i in range(n):

        i = i + 1

        for j in range(n):

            j = j + 1

            for k in range(n):

                k = k + 1

                ij = math.gcd(i,j)

                ans = ans + math.gcd(ij,k)



print(ans)

n = int(eval(input()))


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


ans = 0
if n == 1:
    ans = 1
else:
    for i in range(n):
        i = i + 1
        for j in range(n):
            j = j + 1
            for k in range(n):
                k = k + 1
                ij = gcd(i, j)
                ans = ans + gcd(ij, k)
print(ans)

import math

n = int(eval(input()))
ans = 0
if n == 1:
    ans = 1
else:
    for i in range(n):
        i = i + 1
        for j in range(n):
            j = j + 1
            for k in range(n):
                k = k + 1
                ij = math.gcd(i, j)
                ans = ans + math.gcd(ij, k)
print(ans)

+import math + - - -def gcd(a, b): -    while b: -        a, b = b, a % b -    return a - - -                ij = gcd(i, j) -                ans = ans + gcd(ij, k) +                ij = math.gcd(i, j) +                ans = ans + math.gcd(ij, k)