n = int(eval(input()))



def gcd(a,b):

  ma = max(a,b)

  mb = min(a,b)

  jy = ma % mb

  if jy == 0 :

    return mb

  else:

    return gcd(mb,jy)

sum = 0

for i in range(n):

  for j in range(n):

    for k in range(n):

      sum += gcd(i+1,gcd(j+1,k+1))



print(sum)
n = int(eval(input()))

 

def gcd(a,b):

  ma = max(a,b)

  mb = min(a,b)

  jy = ma % mb

  if jy == 0 :

    return mb

  else:

    return gcd(mb,jy)

sum = 0

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

  sum += i



for i in range(1,n):

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

    sum += 6 * gcd(i,j)



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

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

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

      sum += 6 * gcd(i,gcd(j,k))

 

print(sum)

n = int(eval(input()))


def gcd(a, b):
    ma = max(a, b)
    mb = min(a, b)
    jy = ma % mb
    if jy == 0:
        return mb
    else:
        return gcd(mb, jy)


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

n = int(eval(input()))


def gcd(a, b):
    ma = max(a, b)
    mb = min(a, b)
    jy = ma % mb
    if jy == 0:
        return mb
    else:
        return gcd(mb, jy)


sum = 0
for i in range(1, n + 1):
    sum += i
for i in range(1, n):
    for j in range(i + 1, n + 1):
        sum += 6 * gcd(i, j)
for i in range(1, n - 1):
    for j in range(i + 1, n):
        for k in range(j + 1, n + 1):
            sum += 6 * gcd(i, gcd(j, k))
print(sum)

-for i in range(n): -    for j in range(n): -        for k in range(n): -            sum += gcd(i + 1, gcd(j + 1, k + 1)) +for i in range(1, n + 1): +    sum += i +for i in range(1, n): +    for j in range(i + 1, n + 1): +        sum += 6 * gcd(i, j) +for i in range(1, n - 1): +    for j in range(i + 1, n): +        for k in range(j + 1, n + 1): +            sum += 6 * gcd(i, gcd(j, k))