def gcd(a, b):

    while b != 0 :

        t = a % b

        a = b

        b = t

    return a

        

sum = 0

N=int(eval(input("")))

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

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

        x = gcd(a, b)

        if x == 1:

            sum = sum + N

        elif x == 2:

            sum = sum + (N + 1) // 2 + N // 2 * 2

        else:

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

                sum = sum + gcd(x, c)

print(sum)
def gcd(a, b):

    while b != 0 :

        t = a % b

        a = b

        b = t

    return a

        

sum = 0

N=int(eval(input("")))

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

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

        x = gcd(a, b)

        if x == 1:

            sum = sum + N

        elif x == 2:

            sum = sum + (N + 1) // 2 + N // 2 * 2

        elif x == 3:

            sum = sum + N // 3 * 3 + (N - N // 3)

        else:

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

                sum = sum + gcd(x, c)

print(sum)
def gcd(a, b):
    while b != 0:
        t = a % b
        a = b
        b = t
    return a


sum = 0
N = int(eval(input("")))
for a in range(1, N + 1):
    for b in range(1, N + 1):
        x = gcd(a, b)
        if x == 1:
            sum = sum + N
        elif x == 2:
            sum = sum + (N + 1) // 2 + N // 2 * 2
        else:
            for c in range(1, N + 1):
                sum = sum + gcd(x, c)
print(sum)

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


sum = 0
N = int(eval(input("")))
for a in range(1, N + 1):
    for b in range(1, N + 1):
        x = gcd(a, b)
        if x == 1:
            sum = sum + N
        elif x == 2:
            sum = sum + (N + 1) // 2 + N // 2 * 2
        elif x == 3:
            sum = sum + N // 3 * 3 + (N - N // 3)
        else:
            for c in range(1, N + 1):
                sum = sum + gcd(x, c)
print(sum)

+        elif x == 3: +            sum = sum + N // 3 * 3 + (N - N // 3)