import math

from functools import reduce



def gcd(*numbers):

    return reduce(math.gcd, numbers)



x=0

k=int(eval(input()))

r = list(range(1, k + 1))

x = sum([gcd(a, b, c) for a in r for b in r for c in r])

print(x)

import math

from functools import reduce



def gcd(*numbers):

    return reduce(math.gcd, numbers)



x=0

k=int(eval(input()))



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

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

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

      x+=gcd(i,j,l)



print(x)

import math
from functools import reduce


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


x = 0
k = int(eval(input()))
r = list(range(1, k + 1))
x = sum([gcd(a, b, c) for a in r for b in r for c in r])
print(x)

import math
from functools import reduce


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


x = 0
k = int(eval(input()))
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            x += gcd(i, j, l)
print(x)

-r = list(range(1, k + 1)) -x = sum([gcd(a, b, c) for a in r for b in r for c in r]) +for i in range(1, k + 1): +    for j in range(1, k + 1): +        for l in range(1, k + 1): +            x += gcd(i, j, l)