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

K = int(eval(input()))



def gcd(p, q):

  if(p % q == 0):

    return q

  else:

    return gcd(q, p % q)



sum1 = 0

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

  for b in range(a+1, K+1):

    for c in range(b+1, K+1):

      sum1 += gcd(a, gcd(b, c))



sum2 = 0

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

  for c in range(a+1, K+1):

      sum2 += gcd(a, c)



sum3 = 0

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

  sum3 += a



sum = sum1*6 + sum2*6 + sum3

print(sum)

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

K = int(eval(input()))



def gcd(p, q):

  if(p % q == 0):

    return q

  else:

    return gcd(q, p % q)



sum1 = 0

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

  for b in range(c+1, K+1):

    d = gcd(b, c)

    for a in range(b+1, K+1):

      sum1 += gcd(a, d)



sum2 = 0

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

  for c in range(a+1, K+1):

      sum2 += gcd(a, c)



sum3 = 0

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

  sum3 += a



sum = sum1*6 + sum2*6 + sum3

print(sum)

# -*- coding: utf-8 -*-
K = int(eval(input()))


def gcd(p, q):
    if p % q == 0:
        return q
    else:
        return gcd(q, p % q)


sum1 = 0
for a in range(1, K + 1):
    for b in range(a + 1, K + 1):
        for c in range(b + 1, K + 1):
            sum1 += gcd(a, gcd(b, c))
sum2 = 0
for a in range(1, K + 1):
    for c in range(a + 1, K + 1):
        sum2 += gcd(a, c)
sum3 = 0
for a in range(1, K + 1):
    sum3 += a
sum = sum1 * 6 + sum2 * 6 + sum3
print(sum)

# -*- coding: utf-8 -*-
K = int(eval(input()))


def gcd(p, q):
    if p % q == 0:
        return q
    else:
        return gcd(q, p % q)


sum1 = 0
for c in range(1, K + 1):
    for b in range(c + 1, K + 1):
        d = gcd(b, c)
        for a in range(b + 1, K + 1):
            sum1 += gcd(a, d)
sum2 = 0
for a in range(1, K + 1):
    for c in range(a + 1, K + 1):
        sum2 += gcd(a, c)
sum3 = 0
for a in range(1, K + 1):
    sum3 += a
sum = sum1 * 6 + sum2 * 6 + sum3
print(sum)

-for a in range(1, K + 1): -    for b in range(a + 1, K + 1): -        for c in range(b + 1, K + 1): -            sum1 += gcd(a, gcd(b, c)) +for c in range(1, K + 1): +    for b in range(c + 1, K + 1): +        d = gcd(b, c) +        for a in range(b + 1, K + 1): +            sum1 += gcd(a, d)