# -*- coding: utf-8 -*-

K = int(eval(input()))



# lcm & gcd not math library

def gcd(a, b):

    while b:

        a, b = b, a % b

    return a



from functools import reduce

def gcd_multi(num_list):

    return reduce(gcd, num_list)



ans = 0

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

    for j in range(i, K + 1):

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

            if i == j and j == k:

                dup_num = 1

            elif i == j or j == k:

                dup_num = 3

            else:

                dup_num = 6

            ans += gcd_multi([i, j, k]) * dup_num



print(ans)
# -*- coding: utf-8 -*-

K = int(eval(input()))



# lcm & gcd not math library

def gcd(a, b):

    while b:

        a, b = b, a % b

    return a

ans = 0

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

    for j in range(i, K + 1):

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

            if i == j and j == k:

                dup_num = 1

            elif i == j or j == k:

                dup_num = 3

            else:

                dup_num = 6

            ans += gcd(gcd(i, j), k) * dup_num



print(ans)
# -*- coding: utf-8 -*-
K = int(eval(input()))
# lcm & gcd not math library
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


from functools import reduce


def gcd_multi(num_list):
    return reduce(gcd, num_list)


ans = 0
for i in range(1, K + 1):
    for j in range(i, K + 1):
        for k in range(j, K + 1):
            if i == j and j == k:
                dup_num = 1
            elif i == j or j == k:
                dup_num = 3
            else:
                dup_num = 6
            ans += gcd_multi([i, j, k]) * dup_num
print(ans)

# -*- coding: utf-8 -*-
K = int(eval(input()))
# lcm & gcd not math library
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


ans = 0
for i in range(1, K + 1):
    for j in range(i, K + 1):
        for k in range(j, K + 1):
            if i == j and j == k:
                dup_num = 1
            elif i == j or j == k:
                dup_num = 3
            else:
                dup_num = 6
            ans += gcd(gcd(i, j), k) * dup_num
print(ans)

- - -from functools import reduce - - -def gcd_multi(num_list): -    return reduce(gcd, num_list) -            ans += gcd_multi([i, j, k]) * dup_num +            ans += gcd(gcd(i, j), k) * dup_num