import math



k = int(eval(input()))

s = 0

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

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

        s1 = math.gcd(i, j)

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

            s += math.gcd(k, s1)

print(s)

import math

from functools import reduce





def gcd_list(numbers):

    return reduce(math.gcd, numbers)





k = int(eval(input()))

s = 0

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

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

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

            s += gcd_list([i, j, k])

print(s)

import math

k = int(eval(input()))
s = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        s1 = math.gcd(i, j)
        for k in range(1, k + 1):
            s += math.gcd(k, s1)
print(s)

import math
from functools import reduce


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


k = int(eval(input()))
s = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for k in range(1, k + 1):
            s += gcd_list([i, j, k])
print(s)

+from functools import reduce + + +def gcd_list(numbers): +    return reduce(math.gcd, numbers) + -        s1 = math.gcd(i, j) -            s += math.gcd(k, s1) +            s += gcd_list([i, j, k])