from math import gcd

k=int(eval(input()))

ans=0

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

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

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

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

print(ans)
from math import gcd

from collections import Counter

k=int(eval(input()))

t=[]

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

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

    t.append(gcd(a,b))      

t=Counter(t)

ans=0

for d,e in list(t.items()):

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

    g=gcd(c,d)

    ans+=g*e

print(ans)

from math import gcd

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

from math import gcd
from collections import Counter

k = int(eval(input()))
t = []
for a in range(1, k + 1):
    for b in range(1, k + 1):
        t.append(gcd(a, b))
t = Counter(t)
ans = 0
for d, e in list(t.items()):
    for c in range(1, k + 1):
        g = gcd(c, d)
        ans += g * e
print(ans)

+from collections import Counter -ans = 0 +t = [] -        for c in range(1, k + 1): -            ans += gcd(gcd(a, b), c) +        t.append(gcd(a, b)) +t = Counter(t) +ans = 0 +for d, e in list(t.items()): +    for c in range(1, k + 1): +        g = gcd(c, d) +        ans += g * e