CodeEff/ECCO huggingface dataset:
# 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)


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):
#      print(i,j,k,gcd(i,j,k))
      c+=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):
    w=math.gcd(i,j)
    for k in range(1,k+1):
      c+=math.gcd(w,k)
print(c)
# Original solution
K = int(eval(input()))
memo = {}
def gcd(x,y):
    if x < y:
        x,y = y,x
    if (x,y) in memo:return memo[(x,y)]
    if y == 0:return x
    memo[(x,y)] = gcd(y,x%y)
    return memo[(x,y)]
ans = 0
temp = []
for i in range(1,K+1):
    for j in range(1,K+1):
        temp.append(gcd(i,j))
for i in range(1,K+1):
    for num in temp:
        ans += gcd(i,num)
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):
    for x in range(1,k+1):
      ans += math.gcd(i,math.gcd(j,x))
print(ans)
# Original solution
k = int(eval(input()))
import math
ans = 0
for i in range(1,k+1):
  for j in range(1,k+1):
    for x in range(1,k+1):
      ans += math.gcd(i,math.gcd(j,x))
print(ans)

# Optimized solution
import math
 
k = int(eval(input())) + 1
ans = 0
 
for a in range(1, k):
    for b in range(1, k):
        d = math.gcd(a, b)
        for c in range(1, k):
            ans += math.gcd(d, c)
 
print(ans)
# Original solution
K = int(eval(input()))
 
from itertools import product
kumi = product(list(range(1, K+1)), repeat=3)
 
from math import gcd
 
memo = [[None for i in range(K+1)] for i in range(K+1)]
# memo2 = {}
 
ans = 0
for a, b, c in kumi:
    a, b, c = sorted([a, b, c])
    if memo[a][b] is not None:
        v = memo[a][b]
    else:
        v = gcd(a, b)
        memo[a][b] = v
        memo[b][a] = v
    d = gcd(v, c)
    ans += d
 
print(ans)

# Optimized solution
K = int(eval(input())) 
from math import gcd
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)
# Original 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)

# Optimized solution
from math import gcd
 
n = int(eval(input()))
 
ans = 0
 
for i in range(1,n+1):
  for j in range(1,n+1):
    for k in range(1,n+1):
      ans += gcd(gcd(i,j),k)
      
print(ans)
# Original solution
import math
# メモを残す
K = int(eval(input())) + 1
dic = {}
ans = 0
for a in range(1,K):
    for b in range(1,K):
        for c in range(1,K):
            # 大きい順にソートする
            l = tuple(sorted([a,b,c]))
            if l in dic:
                ans += dic[l]
            else:
                # 最大公約数を求める
                tmp_l = tuple([l[0], l[1]])
                if tmp_l in l:
                    gcd_ab = l[tmp_l]
                else:
                    gcd_ab = math.gcd(l[0], l[1])
                    dic[tmp_l] = gcd_ab

                if gcd_ab < c:
                    tmp_l = tuple([gcd_ab, c])
                else:
                    tmp_l = tuple([c, gcd_ab])

                if tmp_l in l:
                    gcd = l[tmp_l]
                else:
                    gcd = math.gcd(gcd_ab, c)
                    dic[tmp_l] = gcd
                dic[l] = gcd
                ans+=gcd
print(ans)

# Optimized solution
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(a, gcd(b, c))
print(ans)
# Original solution
import math
K=int(eval(input()))
S=0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            x=math.gcd(a,b)
            S+=math.gcd(x,c)
print(S)


# Optimized solution
import math
import itertools
K=int(eval(input()))
l=list(itertools.combinations_with_replacement(list(range(1,K+1)),3))
S=0
for i in l:
    a=i[0]
    b=i[1]
    c=i[2]
    x=math.gcd(a,b)
    if a==b==c:
        S+=math.gcd(x,c)
    elif a==b or b==c or c==a:
        S+=math.gcd(x,c)*3
    else:
        S+=math.gcd(x,c)*6   
print(S)
# Original solution
from math import gcd
def main():
    ans = 0
    k = int(eval(input()))
    for i in range(k):
        for j in range(k):
            for l in range(k):
                ans += gcd(i+1,gcd(j+1,l+1))
    print(ans)


if __name__ == "__main__":
    main()

# Optimized solution
from math import gcd
def main():
    ans = 0
    k = int(eval(input()))
    for i in range(1,1+k):
        for j in range(1,1+k):
            for l in range(1,1+k):
                ans += gcd(i,gcd(j,l))
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
import itertools
K = int(eval(input()))
ans = 0
S = list(range(1,K+1))
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) 
for v in itertools.combinations_with_replacement(S, 3):
  if v[0] == v[1] == v[2]:
    ans += v[0]
  elif v[0] != v[1] and v[1] != v[2] and v[0] != v[2]:
    ans += gcd(gcd(v[0],v[1]),v[2])*6
  else:
    ans += gcd(gcd(v[0],v[1]),v[2])*3

print(ans)

# Optimized solution
import itertools
K = int(eval(input()))
ans = 0
S = list(range(1,K+1))
def gcd(a,b):
  while a != 0 or b != 0:
    if a % b == 0:
      return min(a,b)
    a, b = b, a % b
for v in itertools.combinations_with_replacement(S, 3):
  if v[0] == v[1] == v[2]:
    ans += v[0]
  elif v[0] != v[1] and v[1] != v[2] and v[0] != v[2]:
    ans += gcd(gcd(v[0],v[1]),v[2])*6
  else:
    ans += gcd(gcd(v[0],v[1]),v[2])*3

print(ans)
# Original solution
def gcd(a, b):
    for i in range(100):
      a, b = b, a%b
      if b == 0:
        return a
  
K = int(eval(input()))
A = B = C = [i for i in range(1, K+1)]
cnt = sum([gcd(gcd(a,b),c) for a in A for b in B for c in C])   
print(cnt)

# Optimized solution
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
K = int(eval(input()))
A = B = C = [i for i in range(1, K+1)]

L = [gcd(a,b) for a in A for b in B]

cnt = sum([gcd(l,c) for l in L for c in C])   
print(cnt)
# Original solution
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
k=int(eval(input()))
t=0
for i in range(k):
  for j in range(k):
    for l in range(k):
      t+=gcd((i+1),(j+1),(l+1))
print(t)

# Optimized solution
i=int(eval(input()))
a=[0, \
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]
print((a[i]))
# 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):
            ans+=math.gcd(math.gcd(i,j), l)
            #print(gcd(i,j,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):
        for l in range(1,k+1):
            ans+=gcd(gcd(i,j), l)
            #print(gcd(i,j,l))
print(ans)
# Original solution
k = int(eval(input()))
ans = 0

import math
from functools import reduce

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

import itertools
A = list(itertools.product(list(range(1,k+1)), repeat=3))

for i in range(len(A)):
    ans += gcd_list(A[i])
    
if k == 1:
    print((1))
elif k == 2:
    print((9))
else:
    print(ans)

# Optimized solution
import math
from functools import reduce

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

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(x,y,z)
            
print(ans)
# Original solution
import math
from functools import reduce

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

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(x,y,z)
            
print(ans)


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

import math

for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            ans += math.gcd(i,math.gcd(j,k))
            
print(ans)
# Original solution
# C - Sum of gcd of Tuples (Easy)
import math

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

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

print(s)


# Optimized solution
# C - Sum of gcd of Tuples (Easy)

import math

k = int(eval(input()))
s = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        gcdab = math.gcd(a,b)
        if  gcdab== 1:
            s += k
        else:
            for c in range(1,k+1):
                s += math.gcd(gcdab,c)

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


# Optimized solution
import math

K = int(eval(input()))

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

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


def gcd_3(x, y, z):
    x_y = gcd(x, y)
    return gcd(x_y, z)


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

sum_list = []


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 math
k = int(eval(input()))
s = 0
box = [0]*(k+1)
for l in range (1,k+1):
     for m in range (1, k+1):
          box[math.gcd(l,m)] += 1
for l in range (1,k+1):
     for n in range (1, k+1):
          s += math.gcd(l,n)*box[l]
print(s)
# Original solution
from math import gcd

n = int(eval(input()))

gcd_dic = {}
ans = 0
for i in range(1, n + 1):
    if i == 1:
        ans += n ** 2
        continue
    for j in range(1, n + 1):
        if i == 1:
            ans += n
            continue
        for k in range(1, n + 1):
            if i == 1:
                ans += 1
                continue
            comb = tuple(sorted([i, j, k]))
            if comb not in gcd_dic:
                gcd_dic[comb] = gcd(gcd(i, j), k)
            ans += gcd_dic[comb]
print(ans)

# Optimized solution
answer = [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]
n = int(eval(input()))
print((answer[n - 1]))
# Original solution
answer = [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]
n = int(eval(input()))
print((answer[n - 1]))

# Optimized solution
k = int(eval(input()))
n = 3
cnt = [0] * (k + 1)

for i in range(k, 0, -1):
    cnt[i] = (k // i) ** n
    multiple = i * 2
    while multiple <= k:
        cnt[i] -= cnt[multiple]
        multiple += i

print((sum((i* cnt[i] for i in range(1, k + 1)))))
# Original solution
k = int(eval(input()))
n = 3
cnt = [0] * (k + 1)

for i in range(k, 0, -1):
    cnt[i] = (k // i) ** n
    for j in range(i * 2, k + 1, i):
        cnt[i] -= cnt[j]

print((sum((i* cnt[i] for i in range(1, k + 1)))))


# Optimized solution
k = int(eval(input()))
cnt = [0] * (k + 1)

for i in range(k, 0, -1):
    cnt[i] = (k // i) ** 3
    for j in range(i * 2, k + 1, i):
        cnt[i] -= cnt[j]

print((sum((i* cnt[i] for i in range(1, k + 1)))))
# Original solution
from collections import defaultdict
def gcd(m,n):
    if n==0:
        return m
    return gcd(n,m%n)
##print(gcd(5,3))
##print(gcd(2,4))
k=int(eval(input()))
d=defaultdict(int)
t=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            if list((i,j,k)) in [list(x) for x in list(d.keys())]:
                t+=d[(i,j,k)]
            else:
                d[tuple(sorted((i,j,k)))]=gcd(i,gcd(j,k))
                t+=d[tuple(sorted((i,j,k)))]
print(t)
                
                
            
    


# Optimized solution
from collections import defaultdict
def gcd(m,n):
    if n==0:
        return m
    return gcd(n,m%n)

k=int(eval(input()))
t=0
for i in range(1,k+1):
    for j in range(1,k+1):
        g=gcd(i,j)
        for k in range(1,k+1):
            if k%g==0:
                t+=g
            elif g%k==0:
                t+=k
            else:
                t+=gcd(g,k)
print(t)
# Original solution
from math import gcd
from functools import reduce
def gcd_list(xs):
    return reduce(gcd, xs)

n = int(eval(input()))
a = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            a += gcd_list([i,j,k])
print(a)

# Optimized solution
from math import gcd

n = int(eval(input()))
a = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        b = gcd(i, j)
        for k in range(1, n+1):
            a += gcd(k, b)
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):
            result += math.gcd(math.gcd(a, b), c)

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):
        r = math.gcd(a, b)
        for c in range(1, K+1):
            result += math.gcd(r, c)

print(result)
# Original solution
import math

K = int(eval(input()))

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

print(total)

# Optimized solution
import math

K = int(eval(input()))

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

print(total)
# Original solution
import math

K = int(eval(input()))

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

print(total)

# Optimized solution
import math

K = int(eval(input()))

total = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        ab = math.gcd(a, b)
        if ab == 1:
            total += K
        else:
            for c in range(1, K + 1):
                total += math.gcd(ab, c)

print(total)
# 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(i, math.gcd(j,k))

print (sum)

# Optimized solution
import math

t = int (eval(input()))
sum = 0

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

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

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

K = int(eval(input()))

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

print(sum_ans)

# Optimized solution
import math

K = int(eval(input()))

sum_ans = 0
gcd_list = []
for i in range(1, K+1):
    for j in range(1, K+1):
        tmp = math.gcd(i, j)
        gcd_list.append(tmp)

for k in range(1, K+1):
    for g in gcd_list:
            tmp = math.gcd(k, g)
            sum_ans += tmp

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

k = int(eval(input()))
ans = 0
for l in range(1,k+1):
  for m in range(1,k+1):
    for n in range(1,k+1):
      ans += gcd(l,m,n)

print(ans)

# Optimized solution
import math
import itertools
def gcd(lst):
  return math.gcd(math.gcd(lst[0],lst[1]), lst[2])

k = int(eval(input()))
lst = [i for i in range(1,k+1)]
itr = itertools.combinations_with_replacement(lst, 3)
ans = 0

for i in itr:
  st = set(i)
  num = len(st)
  if num == 1:
    ans += i[0]
  elif num == 2:
    a,b = st
    ans += math.gcd(a,b) * 3
  else:
    ans += math.gcd(math.gcd(i[0],i[1]), i[2]) * 6

print(ans)
# Original solution
import io


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % 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(c, gcd(a, b))

print(ans)

# Optimized solution
import io


def gcd(a, b):
    while b > 0 :
        a, b = b, a%b

    return a


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(c, gcd(a, b))

print(ans)
# Original solution
import math

sets = dict()

def gcd2(a, b):
    if a > b:
        key = (b, a)
    else:
        key = (a, b)
    
    if key in list(sets.keys()):
        # print("cached")
        return sets[key]
    else:
        # print("stored")
        ans = math.gcd(a, b)
        sets[key] = ans
        return ans

def gcd3(a, b, c):
    return gcd2(gcd2(a, b), c)

n = int(eval(input()))

ans = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            ans += gcd3(i, j, k)

print(ans)


# Optimized solution
import math

sets = dict()

def gcd2(a, b):
    if a > b:
        key = (b, a)
    else:
        key = (a, b)
    
    try:
        # print("cached")
        return sets[key]
    except:
        # print("stored")
        ans = math.gcd(a, b)
        sets[key] = ans
        return ans

n = int(eval(input()))

ans = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        pre = gcd2(i, j)

        for k in range(1, n+1):
            ans += gcd2(pre, k)

print(ans)
# Original solution
n=int(eval(input()))
import math
from functools import reduce
def gcd_list(*numbers):#引数はリスト
    return reduce(math.gcd, numbers)
ans=n**2
for i in range(2,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            ans+=gcd_list(i,j,k)
print(ans)

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

import collections as clt
import math
import itertools as itt

v = []
for j in itt.product(list(range(1,K+1)),repeat=3):
	v.append(list(j))
sum = 0

#print(v)

from functools import reduce

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

for j in v:
	sum += gcd_list(j)
print(sum)

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

import collections as clt
import math
import itertools as itt

sum = 0

#print(v)

from functools import reduce

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

for j in itt.product(list(range(1,K+1)),repeat=3):
	sum += gcd_list(j)
print(sum)