import math



k = int(eval(input()))

ans = 0



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

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

      tmp = math.gcd(i, j)

      

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

          ans = ans + math.gcd(tmp, l)



print(ans)
from math import gcd



k = int(eval(input()))

ans = 0



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

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

      tmp = gcd(i, j)



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

          ans = ans + gcd(tmp, l)



print(ans)
import math

k = int(eval(input()))
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        tmp = math.gcd(i, j)
        for l in range(1, k + 1):
            ans = ans + math.gcd(tmp, l)
print(ans)

from math import gcd

k = int(eval(input()))
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        tmp = gcd(i, j)
        for l in range(1, k + 1):
            ans = ans + gcd(tmp, l)
print(ans)

-import math +from math import gcd -        tmp = math.gcd(i, j) +        tmp = gcd(i, j) -            ans = ans + math.gcd(tmp, l) +            ans = ans + gcd(tmp, l)