CodeEff/ECCO huggingface dataset:
# Original solution
k = int(eval(input()))

from math import gcd
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(a, gcd(b, c))
print(ans)

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

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

from math import gcd
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        ab = gcd(a, b)
        for c in range(1, k+1):
            ans += gcd(ab, c)
print(ans)			

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

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


d = {}
def gcd(a,b,c):
    st = tuple(sorted((a,b,c)))
    if st not in d:
        res = math.gcd(a, math.gcd(b,c))
        d[st] = res
    return d[st]

s=0
for i in range(1,K+1):
    for j in range(1, K+1):
        for l in range(1, K+1):
            s += gcd(i, j, l)
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 l in range(1, K+1):
            s += gcd(i, gcd(j,l))

print(s)
# Original solution
K = int(eval(input()))
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        r = a%b
        a = b
        b = r
    return a
count = 0
temp = list()
for n in range(1, K+1):
    for m in range(1, K+1):
        temp.append(gcd(n, m))
for l in range(1, K+1):
    for j in range(len(temp)):
        p = gcd(l, temp[j])
        count += p
print(count)

# Optimized solution
K = int(eval(input()))
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        r = a%b
        a = b
        b = r
    return a
count = 0
temp = list()
for n in range(1, K+1):
    for m in range(1, n):
        temp.append(gcd(n, m))
for l in range(1, K+1):
    for j in range(len(temp)):
        p = gcd(l, temp[j])
        count += 2 * p
    for k in range(1, K+1):
        q = gcd(l, k)
        count += q
print(count)
# Original solution
import itertools
import math
from functools import reduce

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

N = int(eval(input()))

l = list(range(1,N+1))
tap = list(itertools.product(l, repeat=3))
total = 0
for i in tap:
  total += gcd(i[0],i[1],i[2])
print(total)

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

for i in range(1,n+1):
    for j in range(1,n+1):
        l = math.gcd(i,j)
        for k in range(1,n+1):
            ans += math.gcd(k,l)
print(ans)
# Original solution
k = eval(input())
k = int(k)

ll = []
for i in range(1, k + 1):
    l = []
    for j in range(1, i + 1):
        if i % j == 0:
            l.append(j)
            l.append(i // j)
        if (i // j) < j:
            break
    ll.append(set(l))


sum_k = 0

for i in range(k):
    for j in range(k):
        for l in range(k):
            sum_k += max(ll[i] & ll[j] & ll[l])

print(sum_k)


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

ll = []
for i in range(1, k + 1):
    l = []
    for j in range(1, i + 1):
        if i % j == 0:
            l.append(j)
            l.append(i // j)
        if (i // j) < j:
            break
    ll.append(set(l))


sum_k = 0

for i in range(k):
    i_s = ll[i]
    for j in range(k):
        j_s = ll[j]
        m = max(ll[i] & ll[j])
        if m == 1:
            sum_k += k
            continue
        for l in range(k):
            sum_k += max(ll[i] & ll[j] & ll[l])

print(sum_k)
# Original solution
# -*- coding- utf-8 -*-
# C - Sum of gcd of Triplets (Easy)
# モジュールのインポート
import math
import itertools
from functools import reduce

# 標準入力の取得
K = int(eval(input()))

# 求解処理
def gcd(*numbers):
    return reduce(math.gcd, numbers)

result = 0
for a,b,c in itertools.product(list(range(1, K+1)), repeat=3):
    result += gcd(a, b, c)

# 結果出力
print(result)

# Optimized solution
# -*- coding- utf-8 -*-
# C - Sum of gcd of Triplets (Easy)
# モジュールのインポート
import math
import itertools
from functools import reduce

# 標準入力の取得
K = int(eval(input()))

# 求解処理
result = 0
for a,b in itertools.product(list(range(1, K+1)), repeat=2):
    d = math.gcd(a, b)
    for c in range(1, K+1):
        result += math.gcd(d, c)

# 結果出力
print(result)
# Original solution
import math

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

# Optimized solution
import math

k = int(eval(input()))
total = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        tmp = math.gcd(i, j)
        for k in range(1,k+1):
            total += math.gcd(tmp,k)
print(total)
# Original solution
import math
rst = 0
K = int(eval(input()))
for i in range(1, K + 1):
    for j in range(1, K + 1):
        tmp = math.gcd(i, j)
        for k in range(1, K + 1):
            rst += math.gcd(k, tmp)
print(rst)

# Optimized solution
import math
K = int(eval(input()))
rst = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        tmp = math.gcd(i, j)
        for k in range(1, K + 1):
            rst += math.gcd(tmp, k)
print(rst)
# Original solution
def pgcd(a,b):
    if b==0:
        return a
    else:
        return pgcd(b,a%b)
def tgcd(a,b,c):
    return pgcd(a,pgcd(b,c))
def T(N):
    s=0
    for i in range(1,N+1):
        for j in range(1,N+1):
            for l in range(1,N+1):
                s+=tgcd(i,j,l)
    return s
N=int(eval(input()))
print((T(N)))


# Optimized solution
import math
def tgcd(a,b,c):
    return math.gcd(a,math.gcd(b,c))
def T(N):
    s=0
    for i in range(1,N+1):
        for j in range(1,N+1):
            for l in range(1,N+1):
                s+=tgcd(i,j,l)
    return s
N=int(eval(input()))
print((T(N)))
# Original solution
import math

k = int(eval(input()))


ans = 0
for x in range(1,k+1):
    for y in range(1,k+1):
        for z in range(1,k+1):
            ans += math.gcd(math.gcd(x,y),z)

print(ans)


# Optimized solution
from math import gcd

k = int(eval(input()))


ans = 0
for x in range(1,k+1):
    for y in range(1,k+1):
        for z in range(1,k+1):
            ans += gcd(gcd(x,y),z)

print(ans)
# Original solution
import sys, re
import math
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
 
# 整数リストを連結表示    print(''.join(map(str, list)))
 
# -*- coding: utf-8 -*-
 
k = INT()
sum = 0

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

print(sum)

# Optimized solution
import sys, re
import math
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
 
# 整数リストを連結表示    print(''.join(map(str, list)))
 
# -*- coding: utf-8 -*-
 
k = INT()
sum = 0


def A(value, sum):
    if value == 0:
        print(sum)
    else:
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                sum += math.gcd(math.gcd(value, b), c)
        A(value - 1, sum)

A(k, 0)
# Original solution
k = int(eval(input()))

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

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


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

import math
#from functools import reduce
#def gcd(*numbers):
#    return reduce(math.gcd, numbers)

total = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        tmp = math.gcd(a,b)
        for c in range(1,k+1):
            total += math.gcd(tmp,c)
print (total)
# Original solution
K = int(eval(input()))

import math
from functools import reduce

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

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)


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

import math

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
# 最小公倍数(ユーグリッド互除法)
def gcd(a,b):
  if b == 0:
    return a
  else:
    return gcd( b, a % b)


K = int(eval(input())) +1
mydict = {}

# データパターンを求める式
ans = 0
for h in range(1, K):
  for i in range(1, K):
    for j in range(1, K):
      
      tmp = ''.join(map(str, sorted([h,i,j])))
      if tmp in mydict:
        ans += mydict[tmp]
      else:
        val = gcd(h,gcd(i,j))
        ans += val
        mydict[tmp] = val 

print(ans)


# Optimized solution
# 最小公倍数(ユーグリッド互除法)
def gcd(a,b):
  if b == 0:
    return a
  else:
    return gcd( b, a % b)

K = int(eval(input())) + 1
mydict = {}

# データパターンを求める式
ans = 0
for h in range(1, K):
  ans += gcd(h,gcd(h,h))

  for i in range(h+1, K):
    ans += (gcd(h,gcd(h,i)) * 3)
    ans += (gcd(h,gcd(i,i)) * 3)

    for j in range(i+1, K):
      ans += (gcd(h,gcd(i,j)) * 6)

print(ans)
# Original solution
import math

K = int(eval(input()))

def gcd_(a,b,c):
    t = math.gcd(a,b)
    return(math.gcd(t,c))


sum = 0

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            sum += gcd_(a,b,c)

print(sum)            


# Optimized solution
import math

K = int(eval(input()))

gcd2 = [[0 for i in range(K)] for i in range(K)]

for i in range(K):
    for j in range(K):
        gcd2[i][j] = math.gcd(i+1,j+1)

sum = 0
for i in range(K):
    for j in range(K):
        for k in range(K):
            sum += math.gcd(gcd2[i][j],k+1)

print(sum)
# Original solution
import math
ans=0

K=int(eval(input()))
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      if i==1 or j==1 or k==1:
        ans+=1
      else:
        ans+=math.gcd(i,(math.gcd(j,k)))
print(ans)

# Optimized solution
import math
ans=0

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

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

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


n = int(eval(input()))
ans = 0
t = 0
import math
for i in range(1,n+1):
  for j in range(1,n+1):
#    t = math.gcd(i,j)
    for k in range(1,n+1):
      ans += gcd_list([i,j,k])
print(ans)


# Optimized solution
n = int(eval(input()))
ans = 0
t = 0
import math
for i in range(1,n+1):
  for j in range(1,n+1):
    t = math.gcd(i,j)
    for k in range(1,n+1):
      ans += math.gcd(t,k)
print(ans)
# Original solution
import math
K=int(eval(input()))+1
goke=0
for i in range(1,K):
    for j in range(1,K):
        for k in range(1,K):
            goke=goke+math.gcd(math.gcd(i,j),k)
print(goke)

# Optimized solution
import math
K=int(eval(input()))+1
goke=0
for i in range(1,K):
    for j in range(i,K):
        for k in range(j,K):
            if i==j and i==k:
                goke=goke+i
            elif (i==j and i<k) or (i<j and j==k):
                goke=goke+3*math.gcd(i,k)
            else:
                goke=goke+6*math.gcd(math.gcd(i,j),k)
print(goke)
# Original solution
import math

from functools import reduce

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

k = int(eval(input()))
s = 0
c = 0

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)
            s = s + d

print(s)

# Optimized solution
k = int(eval(input()))
a = [1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]

s = a[k-1]

print(s)
# Original solution
K = int(eval(input()))
import math
from functools import reduce

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


# Optimized solution
K = int(eval(input()))
import math
g = 0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            if i == j and j == k:
                g += math.gcd(math.gcd(i,j),k)
            elif i == j and j != k:
                g += math.gcd(math.gcd(i,j),k) * 3
            elif i != j and j == k:
                g += math.gcd(math.gcd(i,j),k) * 3
            else:
                g += math.gcd(math.gcd(i,j),k) * 6


print(g)
# Original solution
import math
from functools import reduce
k = int(eval(input()))

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




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,j,l)

print(ans)

# Optimized solution
import math
from functools import reduce
k = int(eval(input()))

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

ans = 0

for a in range(1,k+1):
    ans +=gcd(a,a,a)

for a in range(1,k+1):
    for b in range(1,k+1):
        if a!=b:
            ans += 3*gcd(a,a,b)

for a in range(1,k-1):
    for b in range(a+1,k):
        for c in range(b+1,k+1):
            #if a!=b and a!=c and b!=c:
            ans +=6*gcd(a,b,c)


print(ans)
# Original solution
from sys import stdin
import math
import fractions

n = int(stdin.readline().rstrip())

cnt = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            a = math.gcd(i+1, j+1)
            b = math.gcd(a, k+1)
            cnt += b

print(cnt)

# Optimized solution
from sys import stdin
import math
import fractions

n = int(stdin.readline().rstrip())

cnt = 0
for i in range(1, n+1):
    for j in range(i, n+1):
        for k in range(j, n+1):
            a = math.gcd(i, j)
            b = math.gcd(a, k) * 6
            if i == j and j == k:
                b = int(b/6)
            elif i == j or j == k or i == k:
                b = int(b/2)
            #print(str(i) + ' ' + str(j) + ' ' + str(k) + ' : ' + str(b))
            cnt += b

print(cnt)
# Original solution
import math
from functools import reduce
from collections import Counter

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

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

n = int(eval(input()))
ans = ["-".join([str(i+1), str(j+1), str(k+1)])  for i in range(n) for j in range(n) for k in range(n)]
counts = Counter(ans)
ans = [gcd(int(k.split("-")[0]), int(k.split("-")[1]), int(k.split("-")[2])) * v for k, v in list(counts.items())]
print((sum(ans)))

# Optimized solution
import math

n = int(eval(input()))
ans = [math.gcd(i+1, math.gcd(j+1, k+1)) for i in range(n) for j in range(n) for k in range(n)]
print((sum(ans)))
# Original solution
import math
K=int(eval(input()))
def gcd(a,b,c):
    s=math.gcd(a,b)
    s=math.gcd(s,c)
    return s
t=0
for a in range(K):
    for b in range(K):
        for c in range(K):
            t+=gcd(a+1,b+1,c+1)
print(t)

# Optimized solution
import math
K=int(eval(input()))
def gcd(a,b,c):
    s=math.gcd(a,b)
    s=math.gcd(s,c)
    return s
t=0
for a in range(K):
    for b in range(K):
        s=math.gcd(a+1,b+1)
        for c in range(K):
            t+=math.gcd(c+1,s)
print(t)
# Original solution
import math
N=int(eval(input()))
total=0

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

# Optimized solution
from math import gcd
N=int(eval(input()))
total=0

for i in range(1,N+1):
  for j in range(1,N+1):
    for k in range(1,N+1):
      total+=gcd(gcd(i,j),k)
      
print(total)
# Original solution
import math

K = int(eval(input()))
#K = 200
sum = 0

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

print(sum)


# Optimized solution
from math import gcd

K = int(eval(input()))
#K = 200
sum = 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(a, b), c)

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

def gcd(*numbers):
    return reduce(math.gcd,numbers)
Sum=0
K=int(eval(input()))
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
           
            Sum+=gcd(a,b,c)
print(Sum)


# Optimized solution
import math
from math import gcd
gcd_sum=[0]*201
ans =0 
k=int(eval(input()))
for i in range(1,k+1):
    for j in range(1,k+1):
        gcd_sum[i]+=gcd(i,j)


for a in range(1,k+1):
    for b in range(1,k+1):
            g=gcd(a,b)
            ans+=gcd_sum[g]
print(ans)
# Original solution
def gcd(x, y):
  if y==0: return x
  return gcd(y, x%y)
K = int(eval(input()))
res = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      res += gcd(gcd(a, b), c)
print(res)

# Optimized solution
def gcd(x, y):
  if y==0: return x
  return gcd(y, x%y)
K = int(eval(input()))
res = 0
for a in range(1, K+1):
  for b in range(a, K+1):
    for c in range(b, K+1):
      if len(set([a, b, c]))==3: res += gcd(gcd(a, b), c) * 6
      elif len(set([a, b, c]))==2: res += gcd(gcd(a, b), c) * 3
      else: res += gcd(gcd(a, b), c)
print(res)
# Original solution
import math

n = int(eval(input()))
answer = 0
for a in range(1,n+1):
    for b in range(1,n+1):
        for c in range(1,n+1):
            answer += math.gcd(a, math.gcd(b,c))
print(answer)

# Optimized solution
import math

n = int(eval(input()))
answer = 0

for a in range(1,n+1):
    for b in range(1,n+1):
        t = math.gcd(a,b)
        for c in range(1,n+1):
            answer += math.gcd(t,c)
print(answer)
# Original solution
from os import path
import sys
if(path.exists('C:/Users/prana/Desktop/sublime/input.txt')):
    sys.stdin = open("C:/Users/prana/Desktop/sublime/input.txt","r")
    sys.stdout = open("C:/Users/prana/Desktop/sublime/output.txt","w")

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

test_case = 1
while(test_case):
    solve()
    test_case -= 1

# Optimized solution
from os import path
if(path.exists('C:/Users/prana/Desktop/sublime/input.txt')):
    import sys
    sys.stdin = open("C:/Users/prana/Desktop/sublime/input.txt","r")
    sys.stdout = open("C:/Users/prana/Desktop/sublime/output.txt","w")

from math import gcd
def solve():
    ans = 0
    a = int(eval(input())) 
    for i in range(a):
        for j in range(a):
            for k in range(a):
                ans += gcd(k+1,gcd(i+1,j+1))
    print(ans)

test_case = 1
while(test_case):
    solve()
    test_case -= 1
# 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):
        ans_=gcd(i,j)
        for l in range(1,k+1):
            ans+=gcd(ans_,l)
print(ans)


# Optimized 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):
        sub = gcd(i,j)
        for l in range(1,k+1):
            ans += gcd(sub,l)
print(ans)
# Original solution
from math import gcd
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):           
            ans = gcd(a, b)
            ans=gcd(ans,c)
            sum+=ans
print(sum)

# Optimized solution
from math import gcd
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):           
            
            sum+=gcd(gcd(a,b),c)
print(sum)
# Original solution
import math

K = int(eval(input()))

sum = 0

for a in range(K):
    sum += a + 1
    #print(a + 1, a + 1)
    for b in range(K):
        if a < b:
            gcd2_sum = math.gcd(a + 1, b + 1) * 3 * 2
            sum += gcd2_sum
            #print(a + 1, b + 1, gcd2_sum)
            for c in range(K):
                if b < c:
                    gcd3_sum = math.gcd(math.gcd(a + 1, b + 1), c + 1) *  6
                    sum += gcd3_sum
                    #print(a + 1, b + 1, c + 1, gcd3_sum)
print(sum)


# Optimized solution
import math

K = int(eval(input()))

sum = 0

for a in range(1,K + 1):
    sum += a
    #print(a, a)
    for b in range(a + 1,K + 1):
        gcd2_sum = math.gcd(a, b) * 3 * 2
        sum += gcd2_sum
        #print(a, b, gcd2_sum)
        for c in range(b + 1, K + 1):
            gcd3_sum = math.gcd(math.gcd(a, b), c) *  6
            sum += gcd3_sum
            #print(a, b, c, gcd3_sum)
print(sum)
# Original solution
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):
            gcd = []
            #print(i,j,k)
            for l in range(1,min(i,j,k)+1):
                #print(i,j,k,l)
                if  i%l==0 and j%l==0 and k%l==0:
                    gcd.append(l)
                    #print(i,j,k,l)
                #print(gcd)
            ans += max(gcd)
print(ans)


# Optimized solution
K = int(eval(input()))
ans = 0
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

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

def gcd(*numbers):
    return reduce(math.gcd, numbers)
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)

# Optimized solution
K = int(eval(input()))
import math
from functools import reduce

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

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

# Optimized solution
from math import gcd
k = int(eval(input()))
sum = 0

for i in range(1, k+1):
  for j in range(1, k+1):
    for k in range(1, k+1):
      sum += gcd(gcd(i, j), k)
      
print(sum)