import itertools

K = int(eval(input()))

ans = 0

S = list(range(1,K+1))

def gcd(x, y):

    if y == 0:

        return x

    else:

        return gcd(y, x % y) 

for v in itertools.combinations_with_replacement(S, 3):

  if v[0] == v[1] == v[2]:

    ans += v[0]

  elif v[0] != v[1] and v[1] != v[2] and v[0] != v[2]:

    ans += gcd(gcd(v[0],v[1]),v[2])*6

  else:

    ans += gcd(gcd(v[0],v[1]),v[2])*3



print(ans)
import itertools

K = int(eval(input()))

ans = 0

S = list(range(1,K+1))

def gcd(a,b):

  while a != 0 or b != 0:

    if a % b == 0:

      return min(a,b)

    a, b = b, a % b

for v in itertools.combinations_with_replacement(S, 3):

  if v[0] == v[1] == v[2]:

    ans += v[0]

  elif v[0] != v[1] and v[1] != v[2] and v[0] != v[2]:

    ans += gcd(gcd(v[0],v[1]),v[2])*6

  else:

    ans += gcd(gcd(v[0],v[1]),v[2])*3



print(ans)
import itertools

K = int(eval(input()))
ans = 0
S = list(range(1, K + 1))


def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)


for v in itertools.combinations_with_replacement(S, 3):
    if v[0] == v[1] == v[2]:
        ans += v[0]
    elif v[0] != v[1] and v[1] != v[2] and v[0] != v[2]:
        ans += gcd(gcd(v[0], v[1]), v[2]) * 6
    else:
        ans += gcd(gcd(v[0], v[1]), v[2]) * 3
print(ans)

import itertools

K = int(eval(input()))
ans = 0
S = list(range(1, K + 1))


def gcd(a, b):
    while a != 0 or b != 0:
        if a % b == 0:
            return min(a, b)
        a, b = b, a % b


for v in itertools.combinations_with_replacement(S, 3):
    if v[0] == v[1] == v[2]:
        ans += v[0]
    elif v[0] != v[1] and v[1] != v[2] and v[0] != v[2]:
        ans += gcd(gcd(v[0], v[1]), v[2]) * 6
    else:
        ans += gcd(gcd(v[0], v[1]), v[2]) * 3
print(ans)

-def gcd(x, y): -    if y == 0: -        return x -    else: -        return gcd(y, x % y) +def gcd(a, b): +    while a != 0 or b != 0: +        if a % b == 0: +            return min(a, b) +        a, b = b, a % b