CodeEff/ECCO huggingface dataset:
# Original solution
from math import gcd

K = int(eval(input()))

ans = 0

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += gcd(gcd(i, j), k)

print(ans)

# Optimized solution
import sys
from math import gcd

def solve(K: int):

    ans = 0

    for i in range(1, K+1):
        for j in range(1, K+1):
            for k in range(1, K+1):
                ans += gcd(gcd(i, j), k)

    print(ans)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()
# Original solution
import math
N= int(eval(input()))
a=0
b=0
for i in range(1,N+1):
    for j in range(1, N + 1):
        for k in range(1, N + 1):
            b=math.gcd(i,j)
            a+=math.gcd(b,k)
print(a)

# Optimized solution
import math
N= int(eval(input()))
a=0
b=0
for i in range(1,N+1):
    for j in range(1, N + 1):
        b = math.gcd(i, j)
        for k in range(1, N + 1):
            a+=math.gcd(b,k)
print(a)
# Original solution
import math

k = int(eval(input()))
result = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            p = math.gcd(a, b)
            q = math.gcd(p, c)
            result += q
print(result)


# Optimized solution
import math

k = int(eval(input()))
result = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        p = math.gcd(a, b)
        for c in range(1, k + 1):
            q = math.gcd(p, c)
            result += q
print(result)
# Original solution
import math

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

# Optimized solution
import math

k = int(eval(input()))
ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        a = math.gcd(i,j)
        for l in range(1,k+1):
            b = math.gcd(a,l)
            ans += b
print(ans)
# Original solution
from functools import reduce
from math import gcd

K = int(eval(input()))

count = 0

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            a = [i, j, k]
            if 1 in a:
                count += 1
                continue
            else:
                count += reduce(gcd, a)
print(count)


# Optimized solution
from math import gcd

K = int(eval(input()))

count = 0

for i in range(1, K+1):
    for j in range(1, K+1):
        a = gcd(i, j)
        for k in range(1, K+1):
            count += gcd(a, k)
print(count)
# Original solution
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
K=int(eval(input()))
s=0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            s+=gcd(i,j,k)
print(s)      

# Optimized solution
from math import gcd
K=int(eval(input()))
s=0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            s+=gcd(gcd(i,j),k)
print(s)
# Original solution
import math
from functools import reduce

def calc(a, b, c):
    return reduce(math.gcd, set([a, b, c]))

def solve(k):
    import itertools
    pattern = itertools.product(list(range(1, k+1)), repeat=3)

    count = 0
    for x in pattern:
        gcd = calc(x[0], x[1], x[2])
        count += gcd

    return count


k = int(eval(input()))

print((solve(k)))


# Optimized solution
from math import gcd

k = int(eval(input()))

ir = list(range(1, k+1))
jr = list(range(1, k+1))
lr = list(range(1, k+1))

count = 0
for i in ir:
  for j in jr:
    for l in lr:
      count += gcd(i, gcd(j, l))

print(count)
# Original solution
import fractions
import math
import itertools
from functools import reduce

k = int(eval(input()))

total = 0
ran = list(range(1, k + 1))
for i, j, k in itertools.product(ran, ran, ran):
    total += math.gcd(math.gcd(i, j), k)
    
print(total)

# Optimized solution
import math

k = int(eval(input()))

total = 0
ran = list(range(1, k + 1))
for i in ran:
    for j in ran:
        for k in ran:
            total += math.gcd(k, math.gcd(i, j))

    
print(total)
# Original solution

def gcd(a, b):
    if a < b:
        a, b = b, a
    r = a % b
    if r == 0:
        return b
    return gcd(r, b)

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)

# Optimized solution
# K, N = map(int, input().split())
# a = list(map(int, input().split()))

# N = int(input())

def gcd(a, b):
    if a < b:
        a, b = b, a
    r = a % b
    if r == 0:
        return b
    return gcd(r, b)

K = int(eval(input()))

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        n = gcd(a, b)
        for c in range(1, K+1):
            ans += gcd(n, c)

print(ans)
# Original solution
from math import gcd
x=int(eval(input()))
y=0
for a in range(x):
  for b in range(x):
    for c in range(x):
      y+=gcd(gcd(a+1,b+1),c+1)
print(y)

# Optimized solution
from math import gcd
z=list(range(int(eval(input()))))
y=0
for a in z:
  for b in z:
    for c in z:
      y+=gcd(gcd(a+1,b+1),c+1)
print(y)
# Original solution
from math import gcd
z=list(range(int(eval(input()))))
y=0
for a in z:
  for b in z:
    for c in z:
      y+=gcd(gcd(a+1,b+1),c+1)
print(y)


# Optimized solution
from math import gcd
z=list(range(1,1+int(eval(input()))))
y=0
for a in z:
  for b in z:
    for c in z:
      y+=gcd(gcd(a,b),c)
print(y)
# Original solution
from sys import stdin
import sys
import math

K = int(eval(input()))

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

print(amount)


# Optimized solution
import math

K = int(eval(input()))

amount = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        gcd_ab = math.gcd(a, b)
        for c in range(1, K+1):
            amount += math.gcd(gcd_ab, c)

print(amount)
# Original solution
import sys
import math
#import fractions
from functools import reduce
import itertools

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

def gcd_list(numbers):
    return reduce(math.gcd, numbers)


N = II()
l = []
for i in range(1,N+1):
    l.append(i)
ans=0

num = 3 #生成するビット数
bit_list = list(itertools.product(l, repeat=num))

for L in bit_list:
    ans += gcd_list(L)
print(ans)


# Optimized solution
import sys
#import fractions
from math import gcd
import itertools

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

def gcd_list(numbers):
    return reduce(gcd, numbers)

def euclid(p,q):
    if p%q==0:
        return q
    else:
        return euclid(q,p%q)


N = II()

ans=0

for i in range(1, N+1):
    for j in range(1, N+1):
        x = gcd(i,j)
        for k in range(1, N+1):
            ans+=gcd(x,k)


print(ans)
# Original solution
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def main():
    K = int(eval(input()))
    s = 0
    for i in range(1, K+1):
        for j in range(1, K+1):
            for k in range(1, K+1):
                s += gcd(i, j, k)
    print(s)
if __name__ == "__main__":
    main()

# Optimized solution
import math
from functools import reduce
def main():
    K = int(eval(input()))
    s = 0
    for i in range(1, K+1):
        for j in range(1, K+1):
            for k in range(1, K+1):
                s += math.gcd(math.gcd(i, j), k)
    print(s)
if __name__ == "__main__":
    main()
# Original solution
import math

k = int( eval(input()) )
out_sum = 0

for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            out_sum += math.gcd( a, math.gcd(b,c) )

print( out_sum )

# Optimized solution
import math

k = int( eval(input()) )
out_sum = 0

# a==b and b==c
for a in range(1, k+1):
    out_sum += a

# a==b and b!=c
for a in range(2, k+1):
    for b in range(1, a):
        out_sum += 6 * math.gcd(a,b)

# a!=b and b!=c
for a in range(3, k+1):
    for b in range(2, a):
        for c in range(1, b):
            out_sum += 6 * math.gcd( a, math.gcd(b,c) )

print( out_sum )
# Original solution
def gcd(a, b):
    if a < b:
        return gcd(b, a)
    d = a % b
    if d == 0:
        return b
    return gcd(b, d)

def main():
    K = int(eval(input()))
    table = [[0]*K for i in range(K)]
    for i in range(K):
        for j in range(K):
            table[i][j] = gcd(i + 1, j + 1)
    ans = 0
    for i in range(K):
        for j in range(K):
            for k in range(K):
                ans += gcd(i + 1, table[j][k])
    print(ans)

if __name__ == '__main__':
    main()


# Optimized solution
def gcd(a, b):
    if a < b:
        return gcd(b, a)
    d = a % b
    if d == 0:
        return b
    return gcd(b, d)

def main():
    K = int(eval(input()))
    table = [[0]*K for i in range(K)]
    for i in range(K):
        for j in range(K):
            table[i][j] = gcd(i + 1, j + 1)
    ans = 0
    for i in range(K):
        for j in range(K):
            for k in range(K):
                ans += table[i][table[j][k]-1]
    print(ans)

if __name__ == '__main__':
    main()
# Original solution
from  math import  gcd
K = int(eval(input()))

ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for l in range(1, K + 1):
            ans  += gcd(i, gcd(j, l))
            
            
print(ans)


# Optimized solution
K = int(eval(input()))

def func_gcd(a, b):
    if b > a:
        a, b = b, a
    
    while b > 0:
        r = a % b
        a = b
        b = r

    return a

ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for l in range(1, K + 1):
            temp = func_gcd(j, l)
            temp2= func_gcd(i, temp)
            ans += temp2

print(ans)
# Original solution
import math
k = int(eval(input()))
su = 0
for x in range(1, k+1):
  for y in range(1, k+1):
    for z in range(1, k+1):
      i = math.gcd(x, y)
      ans = math.gcd(i, z)
      su += ans
      
print(su)

# Optimized solution
import math
k = int(eval(input()))
su = 0
lis = []
for x in range(1, k+1):
  for y in range(1, k+1):
    a = math.gcd(x, y)
    lis.append(a)

for z in range(1, k+1):
  for p in lis:
    ans = math.gcd(p, z)
    su += ans
  
print(su)
# Original solution
import math
K=int(eval(input()))
c = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      if i == j == k:
        c += i
      elif i == j:
        c += math.gcd(i,k)
      elif i == k:
        c += math.gcd(i,j)
      elif j == k:
        c += math.gcd(i,k)
      else:
        c += math.gcd(math.gcd(i, j), k)
print(c)

# Optimized solution
import math
K=int(eval(input()))
c = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    if math.gcd(i,j) == 1:
      c += K
    else:
      for k in range(1,K+1):
        if i == j == k:
          c += i
        elif i == j:
          c += math.gcd(i,k)
        elif i == k:
          c += math.gcd(i,j)
        elif j == k:
          c += math.gcd(i,k)
        else:
          c += math.gcd(math.gcd(i, j), k)
print(c)
# Original solution
import math
from functools import reduce

K = int(eval(input()))

def gcd_list(numbers):
  return reduce(math.gcd, numbers)

output = 0

for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      output += gcd_list([a, b, c])

print(output)

# Optimized solution
import math
from functools import reduce

K = int(eval(input()))

def gcd(*numbers):
  return reduce(math.gcd, numbers)

output = 0

for a in range(1, K+1):
  for b in range(a, K+1):
    for c in range(b, K+1):
      if a == b == c:
        output += gcd(a, b, c)
      elif a != b and b != c and c != a:
        output += 6 * gcd(a, b, c)
      else:
        output += 3 * gcd(a, b, c)

print(output)
# Original solution
def gcd(x, y):
  if x % y == 0:
    return y
  
  return gcd(y, x % y)


K = int(eval(input()))
count = 0
ab = []

for a in range(1, K+1):
  for b in range(1, K+1):
    ab.append(gcd(a, b))

for c in range(1, K+1):
  for i in ab:
    count += gcd(i, c)

print(count)

# Optimized solution
def gcd(x, y):
  if x % y == 0:
    return y
  
  return gcd(y, x % y)


K = int(eval(input()))
count = 0

# a, b, cが全て一致する場合
count += K * (K+1) / 2

# a, b, cのうち、いずれか二つが一致する場合
for a in range(1, K):
  for b in range(a+1, K+1):
    count += gcd(b, a) * 6

# a, b, cが全て異なる場合
for a in range(1, K-1):
  for b in range(a+1, K):
    ab = gcd(b, a)
    
    for c in range(b+1, K+1):
      count += gcd(c, ab)  * 6

print((int(count)))
# Original solution
def euclidean(a, b):
    r = a % b
    if r == 0:
        return b
    return euclidean(b,r)


N = int(eval(input()))

s = 0

for i in range(N):
    for j in range(N):
        ss = euclidean(i+1,j+1)
        for k in range(N):
            s +=euclidean(ss,k+1)

print(s)

# Optimized solution
import math


N = int(eval(input()))

s = 0

for i in range(N):
    for j in range(N):
        ss = math.gcd(i+1,j+1)
        for k in range(N):
            s +=math.gcd(ss,k+1)

print(s)
# Original solution
k = int(eval(input()))

def gcd_(a, b):
    if a < b:
        a, b = b, a
    while not a % b == 0:
        a, b = b, a % b
    return b

def gcd(a, b, c):
    length = len({a, b, c})
    if length == 1:
        return a
    elif length == 2:
        x, y = {a, b, c}
        return gcd_(x, y)
    else:
        x, y, z = {a, b, c}
        w = gcd_(x, y)
        return gcd_(w, z)

s = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for h in range(1, k + 1):
            p = gcd(i, j, h)
            s += p
            
print(s)

# Optimized solution
k = int(eval(input()))

def gcd_(a, b):
    if a < b:
        a, b = b, a
    while not a % b == 0:
        a, b = b, a % b
    return b

s = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        p = gcd_(i, j)
        if p == 1:
            s += k
        else:
            for h in range(1, k + 1):
                s += gcd_(p, h)
            
print(s)
# Original solution
import math

def tgcd(a,b,c):
    return math.gcd(a,math.gcd(b,c))

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

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += tgcd(i,j,k)

print(ans)

# Optimized solution
import math

K = int(eval(input()))
ans = 0
for a in range(1,K-1):
    for b in range(a+1,K):
        for c in range(b+1,K+1):
            r = math.gcd(math.gcd(a,b),c)
            r *= 6
            ans += r
for a in range(1,K):
    for b in range(a+1,K+1):
        r = math.gcd(a,b)
        r *= 6
        ans += r
for a in range(1,K+1):
    ans += a
print(ans)
# Original solution
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


N=int(eval(input()))
S=0
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            S+=gcd(i,j,k)
print(S)

# Optimized solution
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


N=int(eval(input()))
S=0
T=0
for i in range(1,N+1):
    for j in range(i+1,N+1):
        for k in range(j+1,N+1):
            S+=gcd(i,j,k)
for i in range(1,N+1):
    for j in range(i+1,N+1):
            T+=gcd(i,j,j)
            T+=gcd(i,j,j)
print((6*S+3*T+N*(N+1)//2))
# Original solution
import functools
import math

def euclid(a,b):
    if b ==0:
        return a
    else:
        return euclid(b, a%b)


def gcd(nums):
    return functools.reduce(math.gcd,nums)


#N = list(map(int, input().split()))

K = int(eval(input()))
SUM = 0
for a in range(K):
    a += 1
    for b in range(K):
        b += 1
        for c in range(K):
            c += 1
            NUMS = [a,b,c]
            SUM += euclid(euclid(a,b),c)
            #print("{}, {}".format(NUMS,SUM))
print(("{}".format(SUM)))


# Optimized solution

def euclid(a,b):
    if b ==0:
        return a
    else:
        return euclid(b, a%b)


K = int(eval(input()))
SUM = 0
for a in range(K):
    a += 1
    for b in range(K):
        b += 1
        for c in range(K):
            c += 1
            NUMS = [a,b,c]
            SUM += euclid(euclid(a,b),c)
            #print("{}, {}".format(NUMS,SUM))
print(("{}".format(SUM)))
# Original solution
import math
from functools import reduce

k = int(eval(input()))
sum_gcd = 0

def gcd(*numbers):
    return reduce(math.gcd, numbers)

for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            d = gcd(a, b, c)
            sum_gcd += d
print(sum_gcd)




# Optimized solution
import math

k = int(eval(input()))
rng = list(range(1, k+1))

gcd_ls = [math.gcd(i, j) for i in rng for j in rng]
ans = [math.gcd(i, l) for i in rng for l in gcd_ls]

print((sum(ans)))
# Original solution
def gcd(x,y):
    if y == 0:
        return x
    return gcd(y, x%y)


K = int(eval(input()))
sum = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            A = gcd(a,b)
            B = gcd(A,c)
            sum += B
print(sum)


# Optimized solution
def gcd(x,y):
    if y == 0:
        return x
    return gcd(y, x%y)

K = int(eval(input()))
sum = 0
for a in range(1,K-1):
    for b in range(a+1,K):
        for c in range(b+1,K+1):
            sum += gcd(gcd(a,b),c) * 6

for a in range(1,K+1):
    for b in range(1,K+1):
        sum += gcd(gcd(a,b),b) * 3

for i in range(1,K+1):
    sum -=2*i
    
print(sum)
# Original solution
K = int(eval(input()))
trip = dict()
pair = dict()

def gcd(a, b):
    d = frozenset([a, b])
    if d in pair:
        return pair[d]

    if b == 0:
        pair[d] = a
        return a

    while b:
        a %= b
        a, b = b, a

    pair[d] = a
    return a

def gcd3(K):

    res = 0

    for i in range(1, K+1):
        for j in range(1, K+1):
            for k in range(1, K+1):
                l = frozenset([i, j, k])
                if l in trip:
                    res += trip[l]
                    continue

                x = gcd(i, gcd(j, k))
                # print("i:%d, j:%d, k:%d, x:%d" % (i, j, k, x))
                res += x
                trip[l] = x

    return res

print((gcd3(K)))


# Optimized solution
import math 

K = int(eval(input()))

def sol(K):
    res = 0
    for i in range(1, K+1):
        for j in range(1, K+1):
            t = math.gcd(i, j)
            for k in range(1, K+1):
                res += math.gcd(k, t)

    return res
  
print((sol(K)))
# Original solution
import math
k = int(eval(input()))
a = 0
for m in range(1,k+1):
    for n in range(1,k+1):
        for l in range(1,k+1):
             b = math.gcd(m,n)
             #print("b={}".format(b))
             a = a + math.gcd(b,l)
             #print("a={}".format(a))
print(a)


# Optimized solution
import math
k = int(eval(input()))
a = 0
for m in range(1,k+1):
    for n in range(1,k+1):
        b = math.gcd(m,n)
        for l in range(1,k+1):
            a += math.gcd(l,b)
print(a)
# Original solution
from sys import stdin
import math
# 1行だけ読むやつ

N = int(stdin.readline().rstrip().split()[0])
Sum = 0

for i in range(1, N+1):
    for j in range(1, N+1):
        for k in range(1, N+1):
            temp_gcd = math.gcd(i, j)
            Sum += math.gcd(temp_gcd, k)

print(Sum)

# Optimized solution
from sys import stdin
import math
# 1行だけ読むやつ

N = int(stdin.readline().rstrip().split()[0])
Sum = 0

for i in range(1, N+1):
    for j in range(i, N+1):
        for k in range(j, N+1):
            if i == j and j == k:
                Sum += i
            elif i == j or j == k or k == i:
                temp_gcd = math.gcd(i, j)
                Sum += (math.gcd(temp_gcd, k) * 3)
            else:
                Sum += (math.gcd(temp_gcd, k) * 6) 

print(Sum)
# Original solution
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
K=int(eval(input()))
ans=[]
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans.append(gcd(i,j,k))
print((sum(ans)))   

# Optimized solution
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
K=int(eval(input()))
ans=0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans+=gcd(i,j,k)
print(ans)
# Original solution
import math
K = int(eval(input()))
ans = 0

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
           ans += math.gcd(math.gcd(i, j), k)
print(ans)

# Optimized solution
import math
K = int(eval(input()))
ans = 0

for i in range(1, K+1):
    for j in range(1, K+1):
        a = math.gcd(i,j)
        for k in range(1, K+1):
           ans += math.gcd(a, k)
print(ans)
# Original solution
import math
import collections

k = int(eval(input()))
gcd_table = [[0] * k for i in range(k)]
ans = 0
combination_list = [0, 1, 3, 6]
for p in range(1, k+1):
    for q in range(p, k+1):
        if gcd_table[p-1][q-1] == 0:
            tmp_gcd = math.gcd(p, q)
            gcd_table[p-1][q-1] = tmp_gcd
        else:
            tmp_gcd = gcd_table[p-1][q-1]
        for r in range(q, k+1):
            if gcd_table[q-1][r-1] == 0:
                tmp_gcd_2 = math.gcd(q, r)
                gcd_table[q-1][r-1] = tmp_gcd_2
            else:
                tmp_gcd_2 = gcd_table[q-1][r-1]
            unique_num = len(collections.Counter([p, q, r]))
            ans += math.gcd(tmp_gcd, tmp_gcd_2) * combination_list[unique_num]
print(ans)

# Optimized solution
import math
import collections

k = int(eval(input()))
gcd_table = [[0] * k for i in range(k)]
for i in range(1, k+1):
    for j in range(i, k+1):
        gcd_table[i-1][j-1] = math.gcd(i, j)

ans = 0
combination_list = [0, 1, 3, 6]
for p in range(1, k+1):
    for q in range(p, k+1):
        if gcd_table[p-1][q-1] == 0:
            tmp_gcd = math.gcd(p, q)
            gcd_table[p-1][q-1] = tmp_gcd
        else:
            tmp_gcd = gcd_table[p-1][q-1]
        for r in range(q, k+1):
            if gcd_table[q-1][r-1] == 0:
                tmp_gcd_2 = math.gcd(q, r)
                gcd_table[q-1][r-1] = tmp_gcd_2
            else:
                tmp_gcd_2 = gcd_table[q-1][r-1]
            unique_num = len(collections.Counter([p, q, r]))
            ans += math.gcd(tmp_gcd, tmp_gcd_2) * combination_list[unique_num]
print(ans)
# Original solution
from functools import reduce
from math import gcd

log = {}
K = int(eval(input()))
sum_gcd = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            key = str(sorted([a, b, c]))
            if key in log:
                sum_gcd += log[key]
            else:
                result = gcd(gcd(a, b), c)
                sum_gcd += result
                log[key] = result
print(sum_gcd)


# Optimized solution
from math import gcd

log = {}
K = int(eval(input()))
sum_gcd = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            sum_gcd += gcd(gcd(a, b), c)
print(sum_gcd)