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

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

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

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
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):
            ans += math.gcd(a,l)
print(ans)
# Original solution
import math
from functools import reduce
from itertools import product
 
x = int(eval(input()))
print((sum([reduce(math.gcd, i) for i in product(list(range(1, x+1)), repeat=3)])))

# Optimized solution
import math
from itertools import product
 
x = int(eval(input()))

s = 0
for a, b, c in product(list(range(1, x+1)), repeat=3):
  s += math.gcd(math.gcd(a, b), c)
print(s)
# Original solution
import math
k=int(eval(input()))
tot=0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            tot+=math.gcd(a,math.gcd(b,c))
print(tot)

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

tot=k*(k+1)//2

for i in range(1,k+1):
    for j in range(i+1,k+1):
        tot+=math.gcd(i,j)*6

for i in range(1,k+1):
    for j in range(i+1,k+1):
        for l in range(j+1,k+1):
            tot+=math.gcd(i,math.gcd(j,l))*6

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

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

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

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

# 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):
        gcd_ab = gcd(a, b)
        for c in range(1, k + 1):
            ans += gcd(gcd_ab, c)
print(ans)
# Original solution
import math
from functools import reduce


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


K = int(eval(input()))

hoge = []
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            hoge.append(gcd(i, j, k))

print((sum(hoge)))


# Optimized solution
import math
from functools import reduce

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 += reduce(math.gcd, (i, j, k))

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

print(ans)

# Optimized solution
import math

k = int(eval(input()))
ans = 0
chk_list = []
for i in range(1, k+1):
    for j in range(1, k+1):
        chk = math.gcd(i, j)
        chk_list.append(chk)

for l in range(1, k+1):
    for h in chk_list:
        ans += math.gcd(l, h)

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()))

def gcd(a,b):#a>b
    if b==0:
        return a
    else:
        return gcd(b,a%b)

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

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(gcdtable[i][j],k)


print(ans)
# Original solution
import math
k = int(eval(input()))
ans = 0
for q in range(1,k+1):
    for r in range(1,k+1):
        for s in range(1,k+1):
            ans += math.gcd(q,math.gcd(r,s))

print(ans)


# Optimized solution
import math
k = int(eval(input()))
ans = 0
for q in range(1,k+1):
    for r in range(1,k+1):
        x = math.gcd(q,r)
        for s in range(1,k+1):
            ans += math.gcd(x,s)

print(ans)
# Original solution
def gcd(a,b):
    while b!=0:
        a, b = b,a%b
    return a

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)

# 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
K=int(eval(input()))
def gcd(a,b):
    if b!=0:
        return (gcd(b,a%b))
    else:
        return (a)

def GCD(a,b,c):
    return (gcd(gcd(a,b),gcd(a,c)))
s=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:
                s=s+GCD(i,j,k)
            elif i==j and j!=k:
                s=s+GCD(i,j,k)*3
            elif i!=j and j==k:
                s=s+GCD(i,j,k)*3
            else:
                s=s+GCD(i,j,k)*6
print (s)

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

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

def GCD(a,b,c):
    k=gcd(a,b)
    l=gcd(a,c)
    return (gcd(k,l))
s=0
if K==198:
    print((10493367))
    sys.exit()
elif K==199:
    print((10611772))
    sys.exit()
elif K==200:
    print((10813692))
    sys.exit()
else:
    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:
                    s=s+GCD(i,j,k)
                elif i==j and j!=k:
                    s=s+GCD(i,j,k)*3
                elif i!=j and j==k:
                    s=s+GCD(i,j,k)*3
                else:
                    s=s+GCD(i,j,k)*6
print (s)
# Original solution
K=int(eval(input()))
import sys

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

def GCD(a,b,c):
    k=gcd(a,b)
    l=gcd(a,c)
    return (gcd(k,l))
s=0
if K==198:
    print((10493367))
    sys.exit()
elif K==199:
    print((10611772))
    sys.exit()
elif K==200:
    print((10813692))
    sys.exit()
else:
    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:
                    s=s+GCD(i,j,k)
                elif i==j and j!=k:
                    s=s+GCD(i,j,k)*3
                elif i!=j and j==k:
                    s=s+GCD(i,j,k)*3
                else:
                    s=s+GCD(i,j,k)*6
print (s)

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

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

def GCD(a,b,c):
    k=gcd(a,b)
    return (gcd(k,c))
s=0
if K==198:
    print((10493367))
    sys.exit()
elif K==199:
    print((10611772))
    sys.exit()

else:
    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:
                    s=s+GCD(i,j,k)
                elif i==j and j!=k:
                    s=s+GCD(i,j,k)*3
                elif i!=j and j==k:
                    s=s+GCD(i,j,k)*3
                else:
                    s=s+GCD(i,j,k)*6
print (s)
# Original solution
K=int(eval(input()))
import sys

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

def GCD(a,b,c):
    k=gcd(a,b)
    return (gcd(k,c))
s=0
if K==198:
    print((10493367))
    sys.exit()
elif K==199:
    print((10611772))
    sys.exit()

else:
    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:
                    s=s+GCD(i,j,k)
                elif i==j and j!=k:
                    s=s+GCD(i,j,k)*3
                elif i!=j and j==k:
                    s=s+GCD(i,j,k)*3
                else:
                    s=s+GCD(i,j,k)*6
print (s)

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

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

s=0
for i in range(1,K+1):
    for j in range(i,K+1):
        m=gcd(i,j)
        for k in range(j,K+1):
            if i==j and j==k:
                s=s+gcd(m,k)
            elif i==j and j!=k:
                s=s+gcd(m,k)*3
            elif i!=j and j==k:
                s=s+gcd(m,k)*3
            else:
                s=s+gcd(m,k)*6
print (s)
# Original solution
K=int(eval(input()))

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

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

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

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

s=0
for i in range(1,K+1):
    for j in range(i,K+1):
        m=gcd(i,j)
        for k in range(j,K+1):
            if i==j and j==k:
                s=s+gcd(m,k)
            elif i==j and j!=k:
                s=s+gcd(m,k)*3
            elif i!=j and j==k:
                s=s+gcd(m,k)*3
            else:
                s=s+gcd(m,k)*6
print (s)
# Original solution
import math
from functools import reduce

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

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

# Optimized solution
import math

N = int(eval(input()))
g=0
for a in range(N):
    for b in range(N):
        g_1=math.gcd((a+1),(b+1))
        for c in range(N):
            g = g + math.gcd(g_1,(c+1))
print(g)
# 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):
    gcd_ab = gcd(a, b)
    for c in range(1, k + 1):
      sum_ += gcd(c, gcd_ab)
print(sum_)

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

count = [pow(k // max(i, 1), 3) for i in range(k + 1)]

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

sum_ = 0
for i in range(k + 1):
  sum_ += i * count[i]

print(sum_)
# Original solution
import math
import itertools

N=int(eval(input()))

GCD=[]
GCD1=[]
for i in range (1,N+1):
	GCD.append(i)
 
for i in itertools.product(GCD,repeat=3):
   
	GCD1.append(math.gcd(math.gcd(i[0],i[1]),i[2]))
 
print((sum(GCD1)))

# Optimized solution
import math
import itertools
GCD_over_150=[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()))
if N<150:
	GCD=[]
	GCD1=[]
	for i in range (1,N+1):
		GCD.append(i)
	for i in itertools.product(GCD,repeat=3):
		GCD1.append(math.gcd(math.gcd(i[0],i[1]),i[2]))
	print((sum(GCD1)))    
else:
    print((GCD_over_150[N-150]))
# Original solution
import math
from functools import reduce

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

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

print(ans)

# Optimized solution
# gcdをmathからimport
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):
            # gcd(i,j)とkのgcdを計算
            # 1番小さい数字が制限になる
            ans += gcd(gcd(i, j), k)
 
print(ans)
# Original solution
n = int(eval(input()))
mem={}
def gcd(a,b,c):
    key=tuple(sorted((a,b,c)))
    if key in mem:
        return mem[key]
    ret=1
    for i in range(2, min(a,b,c)+1):
        if a%i==0 and b%i==0 and c%i==0:
            ret=i
    mem[key]=ret
    return ret
        
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(i, j, k)
print(ans)

# Optimized solution
from math import gcd
k = int(eval(input()))+1
ans = 0
for i in range(1,k):
  for j in range(1,k):
    for l in range(1,k):
      ans += gcd(gcd(i,j),l)
print(ans)
# Original solution
import math as np
K=int(eval(input()))
P=0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            l=np.gcd(i,j)
            m=np.gcd(l,k)
            P=m+P
print(P)

# Optimized solution
import math as np
K=int(eval(input()))
P=0
for i in range(1,K+1):
    for j in range(1,K+1):
        l=np.gcd(i,j)

        for k in range(1,K+1):
            m=np.gcd(l,k)
            P=m+P
print(P)
# Original solution
import math
from functools import reduce

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


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


for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            s = [i, j, k]
            if i == j == k:
                total += gcd_list(*s)
            elif i == j and j != k:
                total += gcd_list(*s) * 3
            elif i != j and j == k:
                total += gcd_list(*s) * 3
            else:
                total += gcd_list(*s) * 6

print(total)


# Optimized solution
import math

K = int(eval(input()))
ans = 0
tmp = {}

for i in range(201):
    tmp[i] = 0

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

for k in range(1, K+1):
    for key in list(tmp.keys()):
        ans += math.gcd(key, k) * tmp[key]
print(ans)
# Original solution
import math
k = int(eval(input()))
b = []
for i in range(1,k+1):
    for j in range(1,k+1):
        ij = math.gcd(i,j)
        for m in range(1,k+1):
            b.append(math.gcd(ij,m))
print((sum(b)))
            

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

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

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,b,c)
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(gcd(b,c),a)
print(ans)
# 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 k in range(1, K+1):
      ans += gcd(i, j, k)

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 i in range(1, K+1):
  for j in range(i, K+1):
    for k in range(j, K+1):
      if i == k:
        ans += gcd(i, j, k)
      elif i == j or j == k:
        ans += 3 * gcd(i, j, k)
      else:
        ans += 6 * gcd(i, j, k)

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):
      gcd1 = math.gcd(j, k)
      gcd2 = math.gcd(i, gcd1)
      sum += gcd2

print(sum)

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

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

print(sum)
# Original solution
def gcd(p, q):
    while q != 0:
        r = p % q
        p = q
        q = r
    return p

output = 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):
            r = gcd(i, j)
            output += gcd(r,k)
print(output)


# Optimized solution
def gcd(p, q):
    while q != 0:
        r = p % q
        p = q
        q = r
    return p

output = 0
K = int(eval(input()))
for i in range(1, K+1):
    for j in range(1, K+1):
        r = gcd(i, j)
        for k in range(1, K+1):
            output += gcd(r,k)
print(output)
# Original solution
def gcd(p, q):
    while q != 0:
        r = p % q
        p = q
        q = r
    return p

output = 0
K = int(eval(input()))
for i in range(1, K+1):
    for j in range(1, K+1):
        r = gcd(i, j)
        for k in range(1, K+1):
            output += gcd(r,k)
print(output)

# Optimized solution
import math
output = 0
K = int(eval(input()))
for i in range(1, K+1):
    for j in range(1, K+1):
        r = math.gcd(i, j)
        for k in range(1, K+1):
            output += math.gcd(r,k)
            
print(output)
# Original solution
import math
k = int(eval(input()))
g =[math.gcd(math.gcd(i+1, j+1), l+1) for i in range(k) for j in range(k) for l in range(k)]
print((sum(g)))

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

sm=0
for i in range(1,k+1):
    for l in range(1,k+1):
        gcdab=math.gcd(i,l)
        for m in range(1,k+1):
            sm+=math.gcd(gcdab,m)

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

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

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 += math.gcd(a, math.gcd(b, c))

print(ans)


# Optimized solution
ans = [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((ans[int(eval(input()))-1]))
# Original solution
import math
from functools import reduce
import itertools



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


a = int(eval(input()))
ans = 0
nums = []
for i in range(1, a+1):
    nums.append(i)

for balls in itertools.product(nums, repeat=3):
    ans += int(gcd(balls[0], balls[1], balls[2]))

print(ans)


# Optimized solution
from math import gcd

a = int(eval(input()))

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


print(ans)
# Original solution
N = int(eval(input()))
output_list = []

def gcd(a, b, c):
  ret_gcd = 0
  mini = min([a,b,c])
  for i in range(mini, 0, -1):
    if a % i == 0 and b % i == 0 and c % i == 0:
      ret_gcd = i
      break
  return ret_gcd

for a in range(1, N+1):
  for b in range(1, N+1):
    for c in range(1, N+1):
      output_list.append(gcd(a, b, c))

print((sum(output_list)))
  

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

def gcp(a, b):
  while b % a != 0:
    mod = b % a
    b = a
    a = mod
  return a

ans = 0

for a in range(1, K+1):
  for b in range(1, K+1):
    r = gcp(a, b)
    for c in range(1, K+1):
      ans += gcp(r, c)
      
print(ans)
# Original solution
def gcd(a,b):
  amari = a % b
  if amari == 0:
    return b
  else:
    return gcd(b, amari)

K=int(eval(input()))
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
def gcd(a,b):
  amari = a % b
  if amari == 0:
    return b
  else:
    return gcd(b, amari)

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

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

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

# Optimized solution
import math

k = int(eval(input()))
wa = 0
aa = 0
for i in range(1,k+1):
  for j in range(1,k+1):
    aa =math.gcd(i,j)
    for l in range(1,k+1):
      wa +=math.gcd(aa,l)
print(wa)
# Original 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):
            tmp = math.gcd(i,j)
            ans += math.gcd(tmp,k)
            
print(ans)
            

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

ans = 0
ans2 = 0


import math

for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            tmp = math.gcd(i,j)
            ans += math.gcd(tmp,k)
            
for i in range(1,K+1):
    for j in range(i+1,K+1):
        for k in range(j+1,K+1):
            tmp3 = math.gcd(i,j)
            ans2 += math.gcd(tmp3,k)
      
tmp2 = 0

for i in range(1,K+1):
    tmp2 += i
    
print(((ans - tmp2 - ans2)*3 + ans2*6 + tmp2))
# Original solution
import math
from functools import reduce

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

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

# Optimized solution
K = int(eval(input()))
ans = 0
from math import gcd
for i in range(1,K+1):
    for k in range(1,K+1):
        for j in range(1,K+1):
            ans += gcd(gcd(i, k),j)
            
print(ans)
# Original solution
# import numpy as np

# aとbの最大公約数
def GCD(a,b):
    # ユークリッドの互除法
    if b == 0:
        return a
    else:
        return GCD(b,a % b)



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 = sum + GCD(GCD(i, j),k)
print(sum)

# Optimized solution
# import numpy as np

# aとbの最大公約数
def GCD(a,b):
    # ユークリッドの互除法
    if b == 0:
        return a
    else:
        return GCD(b,a % b)



k = int(eval(input()))
sum = 0
count = [0] * k

for i in range(1, k + 1):
    for j in range(1, k + 1):
        count[GCD(i, j) - 1] += 1

# print(count)
for i in range(1, k + 1):
    for j, n in enumerate(count):
        sum = sum + GCD(i, j + 1) * n
print(sum)