import sys

import math



input = sys.stdin.readline



K = int(eval(input()))

ans = 0

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

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

        n = math.gcd(i, j)

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

            if len(set([i, j, l])) == 1:

                ans += math.gcd(n, l)

            elif len(set([i, j, l])) == 2:

                ans += (math.gcd(n, l) * 3)

            else:

                ans += (math.gcd(n, l) * 6)



print(ans)

import sys

import math

 

input = sys.stdin.readline

 

K = int(eval(input()))

ans = 0

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

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

        n = math.gcd(i, j)

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

            ans += math.gcd(n, l)

 

print(ans)
import sys
import math

input = sys.stdin.readline
K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
    for j in range(i, K + 1):
        n = math.gcd(i, j)
        for l in range(j, K + 1):
            if len(set([i, j, l])) == 1:
                ans += math.gcd(n, l)
            elif len(set([i, j, l])) == 2:
                ans += math.gcd(n, l) * 3
            else:
                ans += math.gcd(n, l) * 6
print(ans)

import sys
import math

input = sys.stdin.readline
K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        n = math.gcd(i, j)
        for l in range(1, K + 1):
            ans += math.gcd(n, l)
print(ans)

-    for j in range(i, K + 1): +    for j in range(1, K + 1): -        for l in range(j, K + 1): -            if len(set([i, j, l])) == 1: -                ans += math.gcd(n, l) -            elif len(set([i, j, l])) == 2: -                ans += math.gcd(n, l) * 3 -            else: -                ans += math.gcd(n, l) * 6 +        for l in range(1, K + 1): +            ans += math.gcd(n, l)