def gcd(a, b):

    if b == 0:

        return a

    else:

        return gcd(b, a%b)

k=int(eval(input()))

count=0

count+=k*(k+1)//2

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

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

    if i!=j:

      count+=3*gcd(i,j)

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

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

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

      count+=6*gcd(gcd(a,b),c)

print(count)
def gcd(a, b):

    if b == 0:

        return a

    else:

        return gcd(b, a%b)

k=int(eval(input()))

count=0

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

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

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

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

print(count)

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


k = int(eval(input()))
count = 0
count += k * (k + 1) // 2
for i in range(1, k + 1):
    for j in range(1, k + 1):
        if i != j:
            count += 3 * gcd(i, j)
for a in range(1, k + 1):
    for b in range(a + 1, k + 1):
        for c in range(b + 1, k + 1):
            count += 6 * gcd(gcd(a, b), c)
print(count)

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


k = int(eval(input()))
count = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            count += gcd(gcd(a, b), c)
print(count)

-count += k * (k + 1) // 2 -for i in range(1, k + 1): -    for j in range(1, k + 1): -        if i != j: -            count += 3 * gcd(i, j) -    for b in range(a + 1, k + 1): -        for c in range(b + 1, k + 1): -            count += 6 * gcd(gcd(a, b), c) +    for b in range(1, k + 1): +        for c in range(1, k + 1): +            count += gcd(gcd(a, b), c)