N = int(eval(input())) + 1



Answer = 0



def getGCD(a,b,c):

    if a == b and b == c:

        d = 1

    elif a == b or b == c or c == a:

        d = 3

    else:

        d = 6

        

    surplus = a % c

    while surplus != 0:

        a = int(c)

        c = int(surplus)

        surplus = a % c

    surplus = b % c

    while surplus != 0:

        b = int(c)

        c = int(surplus)

        surplus = b % c

    return c * d





for i in range(1,N):

    for j in range(i,N):

        for k in range(j,N):

            Answer += getGCD(k,j,i)

            

print(Answer)

N = int(eval(input())) + 1



Answer = 0



def getGCD(a,b,c):

    if a == b == c:

        d = 1

    elif a == b or b == c:

        d = 3

    else:

        d = 6

        

    surplus = a % c

    while surplus != 0:

        a,c = c,surplus

        surplus = a % c

    surplus = b % c

    while surplus != 0:

        b,c = c,surplus

        surplus = b % c

    return c * d





for i in range(1,N):

    for j in range(i,N):

        for k in range(j,N):

            Answer += getGCD(k,j,i)

            

print(Answer)

N = int(eval(input())) + 1
Answer = 0


def getGCD(a, b, c):
    if a == b and b == c:
        d = 1
    elif a == b or b == c or c == a:
        d = 3
    else:
        d = 6
    surplus = a % c
    while surplus != 0:
        a = int(c)
        c = int(surplus)
        surplus = a % c
    surplus = b % c
    while surplus != 0:
        b = int(c)
        c = int(surplus)
        surplus = b % c
    return c * d


for i in range(1, N):
    for j in range(i, N):
        for k in range(j, N):
            Answer += getGCD(k, j, i)
print(Answer)

N = int(eval(input())) + 1
Answer = 0


def getGCD(a, b, c):
    if a == b == c:
        d = 1
    elif a == b or b == c:
        d = 3
    else:
        d = 6
    surplus = a % c
    while surplus != 0:
        a, c = c, surplus
        surplus = a % c
    surplus = b % c
    while surplus != 0:
        b, c = c, surplus
        surplus = b % c
    return c * d


for i in range(1, N):
    for j in range(i, N):
        for k in range(j, N):
            Answer += getGCD(k, j, i)
print(Answer)

-    if a == b and b == c: +    if a == b == c: -    elif a == b or b == c or c == a: +    elif a == b or b == c: -        a = int(c) -        c = int(surplus) +        a, c = c, surplus -        b = int(c) -        c = int(surplus) +        b, c = c, surplus