K=int(eval(input()))

import math

ans=0

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

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

    g=math.gcd(a,b)

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

      ans += math.gcd(g,c)

print(ans)
K=int(eval(input()))

import math

ans=0

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

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

    g=math.gcd(a,b)

    if g==1:

      ans += K

      continue

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

      ans += math.gcd(g,c)

print(ans)

K = int(eval(input()))
import math

ans = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        g = math.gcd(a, b)
        for c in range(1, K + 1):
            ans += math.gcd(g, c)
print(ans)

K = int(eval(input()))
import math

ans = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        g = math.gcd(a, b)
        if g == 1:
            ans += K
            continue
        for c in range(1, K + 1):
            ans += math.gcd(g, c)
print(ans)

+        if g == 1: +            ans += K +            continue