memo = [[[-1] * 201 for j in range(201)] for i in range(201)]



def gcd(numbers):

    numbers.sort()

    a = numbers[1]

    b = numbers[0]

    ans = b

    while True:

        q, mod = divmod(a, b)

        if mod == 0:

            break

        a = b

        b = mod

        ans = mod

    return ans



K = int(eval(input()))

numbers = []



for i in range(K, 0, -1):

    for j in range(i, 0, -1):

        for k in range(j, 0, -1):

            numbers.append([i, j, k])



gcd_sum = 0

for number in numbers:

    dup = len(set(number))

    a, b, c = number

    if memo[a][b][c] == -1:

        if dup == 1:

            ans = gcd([gcd([a, b]), c])

        elif dup == 2:

            ans = gcd([gcd([a, b]), c]) * 3

        else:

            ans = gcd([gcd([a, b]), c]) * 6

        memo[a][b][c] = ans

    gcd_sum += memo[a][b][c]



print(gcd_sum)

def gcd(numbers):

    numbers.sort()

    a = numbers[1]

    b = numbers[0]

    ans = b

    while True:

        q, mod = divmod(a, b)

        if mod == 0:

            break

        a = b

        b = mod

        ans = mod

    return ans



K = int(eval(input()))

numbers = []



for i in range(K, 0, -1):

    for j in range(i, 0, -1):

        for k in range(j, 0, -1):

            numbers.append([i, j, k])



gcd_sum = 0

for number in numbers:

    dup = len(set(number))

    a, b, c = number

    if dup == 1:

        gcd_sum += gcd([gcd([a, b]), c])

    elif dup == 2:

        gcd_sum += gcd([gcd([a, b]), c]) * 3

    else:

        gcd_sum += gcd([gcd([a, b]), c]) * 6



print(gcd_sum)

memo = [[[-1] * 201 for j in range(201)] for i in range(201)]


def gcd(numbers):
    numbers.sort()
    a = numbers[1]
    b = numbers[0]
    ans = b
    while True:
        q, mod = divmod(a, b)
        if mod == 0:
            break
        a = b
        b = mod
        ans = mod
    return ans


K = int(eval(input()))
numbers = []
for i in range(K, 0, -1):
    for j in range(i, 0, -1):
        for k in range(j, 0, -1):
            numbers.append([i, j, k])
gcd_sum = 0
for number in numbers:
    dup = len(set(number))
    a, b, c = number
    if memo[a][b][c] == -1:
        if dup == 1:
            ans = gcd([gcd([a, b]), c])
        elif dup == 2:
            ans = gcd([gcd([a, b]), c]) * 3
        else:
            ans = gcd([gcd([a, b]), c]) * 6
        memo[a][b][c] = ans
    gcd_sum += memo[a][b][c]
print(gcd_sum)

def gcd(numbers):
    numbers.sort()
    a = numbers[1]
    b = numbers[0]
    ans = b
    while True:
        q, mod = divmod(a, b)
        if mod == 0:
            break
        a = b
        b = mod
        ans = mod
    return ans


K = int(eval(input()))
numbers = []
for i in range(K, 0, -1):
    for j in range(i, 0, -1):
        for k in range(j, 0, -1):
            numbers.append([i, j, k])
gcd_sum = 0
for number in numbers:
    dup = len(set(number))
    a, b, c = number
    if dup == 1:
        gcd_sum += gcd([gcd([a, b]), c])
    elif dup == 2:
        gcd_sum += gcd([gcd([a, b]), c]) * 3
    else:
        gcd_sum += gcd([gcd([a, b]), c]) * 6
print(gcd_sum)

-memo = [[[-1] * 201 for j in range(201)] for i in range(201)] - - -    if memo[a][b][c] == -1: -        if dup == 1: -            ans = gcd([gcd([a, b]), c]) -        elif dup == 2: -            ans = gcd([gcd([a, b]), c]) * 3 -        else: -            ans = gcd([gcd([a, b]), c]) * 6 -        memo[a][b][c] = ans -    gcd_sum += memo[a][b][c] +    if dup == 1: +        gcd_sum += gcd([gcd([a, b]), c]) +    elif dup == 2: +        gcd_sum += gcd([gcd([a, b]), c]) * 3 +    else: +        gcd_sum += gcd([gcd([a, b]), c]) * 6