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

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

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

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

def gcd(*numbers):
    return reduce(math.gcd, numbers)
  
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 += gcd(i,j,k)
print(total)

# Optimized solution
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
K = int(eval(input()))
total = K*K
for i in range(2,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      total += gcd(i,j,k)
print(total)
# Original solution
def kk(n,m):
    if n<m:
        n,m=m,n
    while  n%m!=0:
        n=n%m
        n,m=m,n
    return m


k= int(eval(input()))
count=0
for p in range(1,k+1):
    for q in range(1,k+1):
        pq=  kk(p,q)
        for r in range(1,k+1):
             pqr= kk(pq,r)
             count= count+ pqr
print(count)

# Optimized solution
def kk(n,m):
    if n<m:
        n,m=m,n
    while  n%m!=0:
        n=n%m
        n,m=m,n
    return m


k= int(eval(input()))
count=0
for p in range(1,k+1):
    for q in range(p,k+1):
        pq=  kk(p,q)
        for r in range(q,k+1):
            pqr= kk(pq,r)
            if p==r:
                 pqr=pqr
            elif p==q or q==r:
                pqr=pqr*3
            else:
                pqr=pqr*6
            count= count+ pqr
print(count)
# Original solution
k = int(eval(input()))
s = 0
import math
from functools import reduce
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      s += reduce(math.gcd, [a,b,c])
print(s)

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

# Optimized solution
K=int(eval(input()))
L1=[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((L1[K-1]))
# 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(math.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(a,b),c)

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

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

N = int(eval(input()))

i = 0
for a, b, c in itertools.product(list(range(1,N+1)), list(range(1,N+1)),list(range(1,N+1))):
    i += gcd(a, b, c)

print(i)

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


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


sum_N = 0
for i in range(1, N + 1):
    for j in range(1, N + 1):
        for k in range(1, N + 1):
            sum_N += gcd(i, j, k)

print(sum_N)


# Optimized solution
from functools import reduce

N = int(eval(input()))


def u_gcd(a, b):
    x = a
    y = b
    while True:
        tmp = x % y
        if tmp == 0:
            return y
        else:
            x = y
            y = tmp


def gcd(*numbers):
    return reduce(u_gcd, numbers)


sum_N = 0
for i in range(1, N + 1):
    for j in range(1, N + 1):
        for k in range(1, N + 1):
            sum_N += gcd(i, j, k)

print(sum_N)
# Original solution
import math
import itertools

k = int(eval(input()))
k_list = []
for i in range(1, k+1):
  k_list.append(i)

total = 0
for i in list(itertools.product(k_list,repeat=3)):
  total += math.gcd(i[0],math.gcd(i[1],i[2]))
  
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):
    if math.gcd(a,b) == 1:
      total += k
    else:
      for c in range(1, k+1):
        total += math.gcd(a,math.gcd(b,c))
    
print(total)
# Original solution
import math
from functools import reduce
s=0
K=int(eval(input()))
for a in range(K):
    for b in range(K):
        for c in range(K):
            x=reduce(math.gcd,(a+1,b+1,c+1))
            s+=x
print(s)

# Optimized solution
import math
from functools import reduce
s=0
K=int(eval(input()))+1
for a in range(1,K):
    for b in range(a,K):
        for c in range(b,K):
            if a==b==c:
                s+=a
                continue
            x=reduce(math.gcd,(a,b,c))
            if a==b or b==c or c==a:
                s+=x*3
            else:
                s+=x*6
print(s)
# Original solution
import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
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(i,j,k)
print(sum)

# Optimized solution
import math
K=int(eval(input()))
ans=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):
            ans+=math.gcd(tmp,k)         
print(ans)
# Original solution
from functools import reduce
import math

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

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

for a in range(1, num + 1):
  for b in range(1, num + 1):
    for c in range(1, num + 1):
      sum += gcd(a, b, c)

print(sum)

# Optimized solution
import math

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

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

print(sum)
# Original solution
import math

N = int(eval(input()))

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

print(sum)


# Optimized solution
from math import gcd

N = int(eval(input()))

sum = 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):
      hoge = gcd(x,k)
      sum+=hoge

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

k = int(eval(input()))
ans = 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):
            ans += gcd(a, b, c)

print(ans)

# Optimized solution
import math

k = int(eval(input()))
ans = 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):
            ans += math.gcd(tmp, c)

print(ans)
# 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
import math

k = int(eval(input()))

ans = 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):
            ans += math.gcd(tmp, c)
print(ans)
# Original solution
import math
import itertools
from functools import reduce
from itertools import product

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

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

l = int(eval(input()))
s = 0
li = list(range(1,l+1))
for i,j,k in product(li, repeat = 3):
  s += gcd(i,j,k)
print(s)

# Optimized solution
import math

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

for i in range(1, l+1):
  for j in range(1, l+1):
    tmp = math.gcd(i,j)
    for j in range(1, l+1):
      s += math.gcd(tmp,j)
  
print(s)
# Original solution
import math
from functools import reduce

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

def main():
    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)

if __name__ == "__main__":
    main()

# Optimized solution
from math import gcd

def main():
    K = int(eval(input()))
    ans = 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):
              ans += gcd(g, k)

    print(ans)

if __name__ == "__main__":
    main()
# Original solution
import heapq
from collections import defaultdict, deque
from math import ceil, factorial, gcd
import sys

sys.setrecursionlimit(10 ** 7)
INF = float("inf")
MOD = 10 ** 9 + 7

si = lambda: input().strip()
ii = lambda: int(eval(input()))
mii = lambda: list(map(int, input().split()))
lmii = lambda: list(map(int, input().split()))
smii = lambda: sorted(map(int, input().split()))


K = ii()

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 heapq
from collections import defaultdict, deque
from math import ceil, factorial, gcd
import sys
import bisect


sys.setrecursionlimit(10 ** 7)
INF = float("inf")
MOD = 10 ** 9 + 7

si = lambda: input().strip()
ii = lambda: int(eval(input()))
mii = lambda: list(map(int, input().split()))
lmii = lambda: list(map(int, input().split()))
smii = lambda: sorted(map(int, input().split()))

K = ii()

ans = 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):
            ans += gcd(g, k)

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

k = int(eval(input()))

lis = [(0)] * (250*250)
ans = 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(b,c)
      lis[b + (250*c)] = (x)
      ans += lis[a + (250*x)]

print(ans)


# Optimized solution
from math import gcd
#from functools import reduce

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

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

x = 0
n = int(eval(input()))+1

for i in range(1,n):
    for j in range(1, n):
        for k in range(1, n):
            x += int(gcd(i,j,k))
print(x)

# Optimized solution
from math import gcd

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

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


temp = []

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            temp.append(gcd(i,j,k))
print((sum(temp)))

# 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(1,K+1):
        for k in range(1,K+1):
            ans += (gcd(i,j,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
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 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):
      value = math.gcd(i,j)
      ans += math.gcd(value,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):
        num = math.gcd(i, j)
        for l in range(1, k+1):
            ans += math.gcd(num, l)

print(ans)
# Original solution
from math import gcd

k = int(eval(input()))
ans = 0
 
for i in range(k):
  for j in range(k):
    for l in range(k):
      ans += gcd(gcd(i+1, j+1),l+1)
      
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

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

def main():
        K = int(eval(input()))

        sum = 0

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

        print(("{}".format(sum)))

if __name__=="__main__":
        main()

# Optimized solution
import math

def main():
        K = int(eval(input()))

        total = 0

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

        print(("{}".format(total)))

if __name__=="__main__":
        main()
# Original solution
from math import gcd

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

for s in range(1, k):
    for t in range(s, k):
        for u in range(t, k):
            if (v := len(set([s, t, u]))) == 1:
                ans += gcd(gcd(s, t), u)
            elif v == 2:
                ans += gcd(gcd(s, t), u) * 3
            else:
                ans += gcd(gcd(s, t), u) * 6
print(ans)



# Optimized solution
from math import gcd

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

for s in range(1, k):
    for t in range(s, k):
        first = gcd(s, t)
        for u in range(t, k):
            if (v := len(set([s, t, u]))) == 1:
                ans += gcd(first, u)
            elif v == 2:
                ans += gcd(first, u) * 3
            else:
                ans += gcd(first, u) * 6
print(ans)
# Original solution

k = int(eval(input()))

gcd_dict = {}

ans = 0
for n in range(k, 0, -1):
   for a in range(n, k + 1, n):
        for b in range(n, k + 1, n):
            for c in range(n, k + 1, n):
                if (a, b, c) not in list(gcd_dict.keys()):
                    gcd_dict[(a, b, c)] = n
                    ans += n

print(ans)


# Optimized solution

k = int(eval(input()))

gcd_cnt = {}

for n in range(k, 0, -1):
    div_all = (k // n) ** 3
    div_dup = 0
    for m in range(n * 2, k + 1, n):
        div_dup += gcd_cnt[m]
    gcd_cnt[n] = div_all - div_dup

ans = 0
for gcd in list(gcd_cnt.keys()):
    ans += gcd * gcd_cnt[gcd]

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

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

k = int(eval(input()))
sum = 0
for x in range(1, k + 1):
	for y in range(1, k + 1):
		for z in range(1, k + 1):
			sum += gcd(x, y, z)
print(sum)

# Optimized solution
import math

k = int(eval(input()))
two = []
total = 0
for x in range(1, k + 1):
	for y in range(1, k + 1):
		two.append(math.gcd(x, y))

for z in range(1, k + 1):
	for i in two:
		total += math.gcd(z, i)
print(total)
# 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()))
s = 0
l = []
for i in range(k):
  for j in range(k):
    l.append(gcd(i+1,j+1))
for h in range(k):
  for n in l:
    s += gcd(h+1, n)
print(s)


# Optimized 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()))
s = 0
l = []
for i in range(k):
  for j in range(k):
    l.append(math.gcd(i+1,j+1))
for h in range(k):
  for n in l:
    s += math.gcd(h+1, n)
print(s)
# Original solution
K = int(eval(input()))
def gcd(x, y):
  a, b = x, y
  while b != 0:
    a, b = b, a % b
  return a
gcds = [[0 for j in range(K)] for i in range(K)]
for i in range(K):
  for j in range(K):
    gcds[i][j] = gcd(i+1, j+1)
S = 0
for i in range(K):
  for j in range(K):
    for k in range(K):
      S += gcds[gcds[j][k]-1][i]
print(S)

# Optimized solution
K = int(eval(input()))
mod = int(1e9) + 7
X = [0 for _ in range(K)]
def doubling(n, m):
  y = 1
  base = n
  while m != 0:
    if m % 2 == 1:
      y *= base
      y %= mod
    base *= base
    base %= mod
    m //= 2
  return y
SS = 0
for i in range(K, 0, -1):
  d = K // i
  S = doubling(d, 3)
  if d > 1:
    for j in range(2, d+1):
      S -= X[j*i-1]
      S %= mod
  X[i-1] = S
  SS += i * S
  SS %= mod
print(SS)
# Original solution
import math
from functools import reduce

def gcd_list(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_list([a,b,c])
print(ans)

# Optimized solution
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
def calc_same_num(s):
    if s[0]==s[1] and s[1]==s[2]:
        return 1
    elif s[0]==s[1] or s[1]==s[2]:
        return 3
    else:
        return 6
    
k = int(eval(input()))
sum_check = 0
a,b,c = 1,1,1
ans = 0
while a<=k and b<=k and c<=k:
    gcd = gcd_list([a,b,c])
    ans += gcd*calc_same_num([a,b,c])
    if c<k:
        c += 1
    elif b<k:
        b += 1
        c = b
    else:
        a += 1
        b = a
        c = a
print(ans)
# 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):

            if a == b == c:
                total += a
                continue

            if a == 1:
                total += a
                continue

            if b == 1:
                total += b
                continue

            if c == 1:
                total += c
                continue

            if a % b == 0:
                total += math.gcd(b,c)
                continue
            
            if b % a == 0:
                total += math.gcd(a,c)
                continue

            total += math.gcd(math.gcd(a,b),c)

print(total)

# Optimized solution
import math

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

a_arr = list()
b_arr = list()

for k in k_arr:
    for a in k_arr:
        a_arr.append(a)

for b in k_arr:
    for k in k_arr:
        b_arr.append(b)

gcds = list(map(math.gcd,a_arr,b_arr))

total = 0
for c in k_arr:
    c_arr = [c] * k * k
    total += sum(map(math.gcd,gcds,c_arr))

print(total)
# Original solution
def gcd2(a, b):
    if b == 0:
        return a
    
    return gcd2(b, a % b)

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

if __name__ == "__main__":
    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 += gcd3(a, b, c)
    
    print(ans)

# Optimized solution
def gcd2(a, b):
    if b == 0:
        return a
    
    return gcd2(b, a % b)

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

if __name__ == "__main__":
    k = int(eval(input()))
    
    ans = 0

    for a in range(1, k + 1):
        for b in range(1, a + 1):
            for c in range(1, b + 1):
                if a == b and b == c and c == a:
                    ans += gcd3(a, b, c)
                elif a == b or b == c or c == a:
                    ans += gcd3(a, b, c) * 3
                else:
                    ans += gcd3(a, b, c) * 6
    
    print(ans)
# Original solution
import math
import itertools
from functools import reduce

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

k = int(eval(input()))

ans = 0 

for a,b,c in itertools.product(list(range(1,k + 1)), repeat=3):
    s = gcd(a,b,c)
    ans += s
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
import math
n=int(eval(input()))

def gcd2(a,b,c):
    d=math.gcd(a,b)
    e=math.gcd(c,d)
    return e
    
s=0
for i1 in range(1,n+1):
    for i2 in range(1,n+1):
        for i3 in range(1,n+1):
            s+=gcd2(i1,i2,i3)

print(s)



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

def gcd2(a,b,c):
    d=math.gcd(a,b)
    e=math.gcd(c,d)
    return e
    
s=0
s1=0
s2=0
s3=0

for i in range(1,n+1):
    s1+=i
    for i2 in range(i+1,n+1):
        s2+=math.gcd(i,i2)
        for i3 in range(i2+1,n+1):
            s3+=gcd2(i,i2,i3)

s=s1+6*s2+6*s3

print(s)