import math

from functools import reduce

n = int(eval(input()))

ans = 0

li = []

buf = n



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

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

        tmp = math.gcd(i,j)

        li.append(tmp)

for i in range(len(li)):

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

        ans += math.gcd(li[i],j)



print(ans)

import math

from functools import reduce

n = int(eval(input()))

ans = 0

li = []

buf = n



def gcd(*numbers):

    return reduce(math.gcd,numbers)



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

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

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

            ans += gcd(i,j,k)



print(ans)

import math
from functools import reduce

n = int(eval(input()))
ans = 0
li = []
buf = n
for i in range(1, n + 1):
    for j in range(1, n + 1):
        tmp = math.gcd(i, j)
        li.append(tmp)
for i in range(len(li)):
    for j in range(1, n + 1):
        ans += math.gcd(li[i], j)
print(ans)

import math
from functools import reduce

n = int(eval(input()))
ans = 0
li = []
buf = n


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


for i in range(1, n + 1):
    for j in range(1, n + 1):
        for k in range(1, n + 1):
            ans += gcd(i, j, k)
print(ans)

+ + +def gcd(*numbers): +    return reduce(math.gcd, numbers) + + -        tmp = math.gcd(i, j) -        li.append(tmp) -for i in range(len(li)): -    for j in range(1, n + 1): -        ans += math.gcd(li[i], j) +        for k in range(1, n + 1): +            ans += gcd(i, j, k)