k = int(eval(input()))



s = 0

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

    for i2 in range(1, i1+1):

        x1, x2 = i1, i2

        while x2 != 0:

            x1, x2 = x2, x1 % x2

        gcd1 = x1

        s2 = i1 == i2

        for i3 in range(i1, k+1):

            x1, x2 = gcd1, i3

            while x2 != 0:

                x1, x2 = x2, x1 % x2

            gcd2 = x1



            s3 = i2 == i3 or i1 == i3

            if s2 and s3:

                s = s + gcd2

            elif s2 or s3:

                s = s + gcd2*3

            else:

                s = s + gcd2*6

print(s)

k = int(eval(input()))



s = 0

# 3つ違う

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

    s = s + i1

    for i2 in range(1, i1):

        x1, x2 = i1, i2

        while x2 != 0:

            x1, x2 = x2, x1 % x2

        gcd1 = x1

        s = s + gcd1 * 6

        for i3 in range(i1+1, k+1):

            x1, x2 = gcd1, i3

            while x2 != 0:

                x1, x2 = x2, x1 % x2

            gcd2 = x1

            s = s + gcd2 * 6



print(s)

k = int(eval(input()))
s = 0
for i1 in range(1, k + 1):
    for i2 in range(1, i1 + 1):
        x1, x2 = i1, i2
        while x2 != 0:
            x1, x2 = x2, x1 % x2
        gcd1 = x1
        s2 = i1 == i2
        for i3 in range(i1, k + 1):
            x1, x2 = gcd1, i3
            while x2 != 0:
                x1, x2 = x2, x1 % x2
            gcd2 = x1
            s3 = i2 == i3 or i1 == i3
            if s2 and s3:
                s = s + gcd2
            elif s2 or s3:
                s = s + gcd2 * 3
            else:
                s = s + gcd2 * 6
print(s)

k = int(eval(input()))
s = 0
# 3つ違う
for i1 in range(1, k + 1):
    s = s + i1
    for i2 in range(1, i1):
        x1, x2 = i1, i2
        while x2 != 0:
            x1, x2 = x2, x1 % x2
        gcd1 = x1
        s = s + gcd1 * 6
        for i3 in range(i1 + 1, k + 1):
            x1, x2 = gcd1, i3
            while x2 != 0:
                x1, x2 = x2, x1 % x2
            gcd2 = x1
            s = s + gcd2 * 6
print(s)

+# 3つ違う -    for i2 in range(1, i1 + 1): +    s = s + i1 +    for i2 in range(1, i1): -        s2 = i1 == i2 -        for i3 in range(i1, k + 1): +        s = s + gcd1 * 6 +        for i3 in range(i1 + 1, k + 1): -            s3 = i2 == i3 or i1 == i3 -            if s2 and s3: -                s = s + gcd2 -            elif s2 or s3: -                s = s + gcd2 * 3 -            else: -                s = s + gcd2 * 6 +            s = s + gcd2 * 6