from math import gcd

K=int(eval(input()))

k=[1,1,1]

g=0

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

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

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

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

      

      

print(g)
from math import gcd

K=int(eval(input()))

g=0

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

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

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

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

for  d in range(1,K):

  for e in range(d+1,K+1):

    g+=gcd(d,e)*6

g+=K*(K+1)//2

print(g)
from math import gcd

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

from math import gcd

K = int(eval(input()))
g = 0
for a in range(1, K - 1):
    for b in range(a + 1, K):
        for c in range(b + 1, K + 1):
            g += gcd(gcd(a, b), c) * 6
for d in range(1, K):
    for e in range(d + 1, K + 1):
        g += gcd(d, e) * 6
g += K * (K + 1) // 2
print(g)

-k = [1, 1, 1] -for a in range(1, K + 1): -    for b in range(1, K + 1): -        for c in range(1, K + 1): -            g += gcd(gcd(a, b), c) +for a in range(1, K - 1): +    for b in range(a + 1, K): +        for c in range(b + 1, K + 1): +            g += gcd(gcd(a, b), c) * 6 +for d in range(1, K): +    for e in range(d + 1, K + 1): +        g += gcd(d, e) * 6 +g += K * (K + 1) // 2