import math



K = int(eval(input()))



sum = 0



for a in range(K):

    sum += a + 1

    #print(a + 1, a + 1)

    for b in range(K):

        if a < b:

            gcd2_sum = math.gcd(a + 1, b + 1) * 3 * 2

            sum += gcd2_sum

            #print(a + 1, b + 1, gcd2_sum)

            for c in range(K):

                if b < c:

                    gcd3_sum = math.gcd(math.gcd(a + 1, b + 1), c + 1) *  6

                    sum += gcd3_sum

                    #print(a + 1, b + 1, c + 1, gcd3_sum)

print(sum)

import math



K = int(eval(input()))



sum = 0



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

    sum += a

    #print(a, a)

    for b in range(a + 1,K + 1):

        gcd2_sum = math.gcd(a, b) * 3 * 2

        sum += gcd2_sum

        #print(a, b, gcd2_sum)

        for c in range(b + 1, K + 1):

            gcd3_sum = math.gcd(math.gcd(a, b), c) *  6

            sum += gcd3_sum

            #print(a, b, c, gcd3_sum)

print(sum)

import math

K = int(eval(input()))
sum = 0
for a in range(K):
    sum += a + 1
    # print(a + 1, a + 1)
    for b in range(K):
        if a < b:
            gcd2_sum = math.gcd(a + 1, b + 1) * 3 * 2
            sum += gcd2_sum
            # print(a + 1, b + 1, gcd2_sum)
            for c in range(K):
                if b < c:
                    gcd3_sum = math.gcd(math.gcd(a + 1, b + 1), c + 1) * 6
                    sum += gcd3_sum
                    # print(a + 1, b + 1, c + 1, gcd3_sum)
print(sum)

import math

K = int(eval(input()))
sum = 0
for a in range(1, K + 1):
    sum += a
    # print(a, a)
    for b in range(a + 1, K + 1):
        gcd2_sum = math.gcd(a, b) * 3 * 2
        sum += gcd2_sum
        # print(a, b, gcd2_sum)
        for c in range(b + 1, K + 1):
            gcd3_sum = math.gcd(math.gcd(a, b), c) * 6
            sum += gcd3_sum
            # print(a, b, c, gcd3_sum)
print(sum)

-for a in range(K): -    sum += a + 1 -    # print(a + 1, a + 1) -    for b in range(K): -        if a < b: -            gcd2_sum = math.gcd(a + 1, b + 1) * 3 * 2 -            sum += gcd2_sum -            # print(a + 1, b + 1, gcd2_sum) -            for c in range(K): -                if b < c: -                    gcd3_sum = math.gcd(math.gcd(a + 1, b + 1), c + 1) * 6 -                    sum += gcd3_sum -                    # print(a + 1, b + 1, c + 1, gcd3_sum) +for a in range(1, K + 1): +    sum += a +    # print(a, a) +    for b in range(a + 1, K + 1): +        gcd2_sum = math.gcd(a, b) * 3 * 2 +        sum += gcd2_sum +        # print(a, b, gcd2_sum) +        for c in range(b + 1, K + 1): +            gcd3_sum = math.gcd(math.gcd(a, b), c) * 6 +            sum += gcd3_sum +            # print(a, b, c, gcd3_sum)