import math

K = int(eval(input()))



def computeGCD(x, y):

    while (y):

        x, y = y, x % y



    return x



sum = 0

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

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

        intermediate = computeGCD(a, b)

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

            sum += computeGCD(c, intermediate)



print(sum)
import math

K = int(eval(input()))



def computeGCD(x, y):

    while (y):

        x, y = y, x % y



    return x



result = list()

sum = 0

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

    intermediate_result = list()

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

        intermediate_result.append(computeGCD(a, b))

    result.append(intermediate_result)



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

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

        intermediate = result[a-1][b-1]

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

            sum += result[intermediate-1][c-1]



print(sum)
import math

K = int(eval(input()))


def computeGCD(x, y):
    while y:
        x, y = y, x % y
    return x


sum = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        intermediate = computeGCD(a, b)
        for c in range(1, K + 1):
            sum += computeGCD(c, intermediate)
print(sum)

import math

K = int(eval(input()))


def computeGCD(x, y):
    while y:
        x, y = y, x % y
    return x


result = list()
sum = 0
for a in range(1, K + 1):
    intermediate_result = list()
    for b in range(1, K + 1):
        intermediate_result.append(computeGCD(a, b))
    result.append(intermediate_result)
for a in range(1, K + 1):
    for b in range(1, K + 1):
        intermediate = result[a - 1][b - 1]
        for c in range(1, K + 1):
            sum += result[intermediate - 1][c - 1]
print(sum)

+result = list() +    intermediate_result = list() -        intermediate = computeGCD(a, b) +        intermediate_result.append(computeGCD(a, b)) +    result.append(intermediate_result) +for a in range(1, K + 1): +    for b in range(1, K + 1): +        intermediate = result[a - 1][b - 1] -            sum += computeGCD(c, intermediate) +            sum += result[intermediate - 1][c - 1]