from math import gcd

import itertools

K=int(eval(input()))

res=0

li=[]

for x in itertools.product(list(range(1,K+1)),repeat=2):

    li.append(gcd(x[0],x[1]))

for x,y in itertools.product(list(range(1,K+1)),li):

    res+=gcd(x,y)

print(res)
from math import *

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
import itertools

K = int(eval(input()))
res = 0
li = []
for x in itertools.product(list(range(1, K + 1)), repeat=2):
    li.append(gcd(x[0], x[1]))
for x, y in itertools.product(list(range(1, K + 1)), li):
    res += gcd(x, y)
print(res)

from math import *

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 -import itertools +from math import * -res = 0 -li = [] -for x in itertools.product(list(range(1, K + 1)), repeat=2): -    li.append(gcd(x[0], x[1])) -for x, y in itertools.product(list(range(1, K + 1)), li): -    res += gcd(x, y) -print(res) +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)