CodeEff/ECCO huggingface dataset:
# 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):
            s+=math.gcd(math.gcd(a,b),c)
print(s)

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


print(counter)

# Optimized solution
from math import gcd
counter = 0
K = int(eval(input()))
for a in range(1,K+1):
    for b in range(1,K+1):
        if gcd(a,b)==1:
            counter += K
        else:
            for c in range(1,K+1):
                d = gcd(a,b)
                counter += gcd(c,d)


print(counter)
# Original solution
import math

N = int(eval(input()))

result = 0

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

print(result)

# Optimized solution
import math

N = int(eval(input()))

result = 0

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

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

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

import sys
K=eval(input())
K=int(K)
L=[]
a=1
b=1
c=1
for i in range(K):
    for j in range(K):
        for m in range(K):
            L.append(gcd(a,b,c))
            c=c+1
        c=1
        b=b+1
    b=1
    c=1
    a=a+1

S=sum(L)
print(S)

# Optimized solution
import math
from functools import reduce

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

import sys
K=eval(input())
K=int(K)
S=0
a=1
b=1
c=1
for i in range(K):
    for j in range(K):
        if gcd(a,b)==1:
            S+=K
        else:
            S+=sum([gcd(a,b,c) for c in range(1,K+1)])
        c=1
        b=b+1
    b=1
    c=1
    a=a+1

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

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):
#         for l in range(1,K+1):
#             sum += math.gcd(math.gcd(i,j),l)
for i in range(1,K+1):
    for j in range(1,K+1):
        if math.gcd(i,j)==1:
            sum += K
        else:
            for l in range(1,K+1):
                sum += math.gcd(math.gcd(i,j),l)


print(sum)
# Original solution
from itertools import product
from functools import reduce
from math import gcd
k = int(eval(input()))
ans = 0
for abc in product([i for i in range(1, k+1)], repeat=3):
    ans += reduce(gcd, abc)
print(ans)


# Optimized solution
from math import gcd
k = int(eval(input()))
double = [gcd(i, j) for i in range(1, k+1) for j in range(1, k+1)]
triple = [gcd(i, j) for i in range(1, k+1) for j in double]
print((sum(triple)))
# Original solution
import math
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 += math.gcd(math.gcd(a,b),c)
      
print(sum)

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

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

import math
from collections import deque
ans = deque()
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            ans.append(math.gcd(math.gcd(i, j), l))
print((sum(ans)))


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

import math
ans = 0
ans1 = 0
ans2 = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        ans1 += math.gcd(i,j)

ans = ans + ans1*3

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

ans += ans2*6
print((ans-sum(list(range(k+1)))*2))
# Original solution
import math
result = 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) :
            result += math.gcd(math.gcd(a ,b), c)

print(result)

# Optimized solution
import math
result = 0
k = int(eval(input()))
for a in range(1, k+1) :
    for b in range(1, k+1) :
        if math.gcd(a ,b) == 1 :
            result += k
        else :
            for c in range(1, k+1) :
                result += math.gcd(math.gcd(a ,b), c)
print(result)
# Original solution
from itertools import permutations, combinations,combinations_with_replacement,product
import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
    
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

def main():
    #n, k = map(int,input().split())
    k = int(eval(input()))
    lists = []
    for i in range(k):
        for j in range(k):
            for l in range(k):
                lists.append((i+1,j+1,l+1))
    
    #for v in combinations_with_replacement(lists,3):
    #    print(v)
    #lists = list(combinations_with_replacement(lists,3))
    #lists2 = set(lists)
    #print(lists)
    #lists2 = [i[0]*100+i[1]*10+i[2] for i in lists]
    #print(lists2)
    k = 0
    for i in lists:
        k = k + gcd(i[0],i[1],i[2])
    print(k)
    """
    koubai = 0
    for i in lists:
        if len(set(i))==1:
            koubai = koubai + gcd(i[0],i[1],i[2])
            #print(koubai)
        elif len(set(i))==2:
            koubai = koubai + 3*gcd(i[0],i[1],i[2])
        else:
            koubai = koubai + 6*gcd(i[0],i[1],i[2])
            #print(koubai)
    print(koubai)
    """



if __name__ == '__main__':
    main()

# Optimized solution
import math

def main():
    #n, k = map(int,input().split())
    k = int(eval(input()))
    lists = []
    sum = 0
    for i in range(k):
        for j in range(k):
            for l in range(k):
                sum = sum + math.gcd(math.gcd(i+1 ,j+1), l+1)
    print(sum)

if __name__ == '__main__':
    main()
# 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)

def main():
    #n, k = map(int,input().split())
    k = int(eval(input()))
    lists = []
    sum = 0
    for i in range(1,k+1):
        for j in range(1,k+1):
            for l in range(1,k+1):
                #print(i,j,l)
                sum = sum + gcd(i,j,l)
    print(sum)

if __name__ == '__main__':
    main()

# Optimized solution
import math

def main():
    #n, k = map(int,input().split())
    k = int(eval(input()))
    lists = []
    sum = 0
    for i in range(1,k+1):
        for j in range(1,k+1):
            for l in range(1,k+1):
                #print(i,j,l)
                sum = sum + math.gcd(math.gcd(i,j),l)
    print(sum)

if __name__ == '__main__':
    main()
# Original solution
import math
input_N = int(eval(input()))
i = j = k =1

l = sum_gcd=0
for i in range(input_N):
    for j in range(input_N):
        for k in range(input_N):
            l +=1
            sum_gcd += math.gcd(math.gcd(i+1,j+1),k+1)
print(sum_gcd)       

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

def gcd_list(numbers):
    return reduce(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_list([i, j, l])
print(ans)

# Optimized solution
from math import gcd
from functools import reduce

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

k = int(eval(input()))
ans = 0
rev = 0
for i in range(1, k + 1):
    for j in range(i, k + 1):
        tmp = gcd(i, j)
        for l in range(j, k + 1):
            if i == j and j == l:
                ans += i
            elif i == j or j == l or l == i:
                ans += gcd(tmp, l) * 3
            else:
                ans += gcd(tmp, l) * 6
print(ans)
# Original solution
import math

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

#
# def gcd(a, b):
#     if a < b:
#         a, b = b, a
#     while a % b != 0:
#         a, b = b, a % b
#     return b


sum_gcd = 0
for l in k_range:
    for m in k_range:
        for n in k_range:
            sum_gcd += math.gcd(n, math.gcd(l, m))

print(sum_gcd)

# Optimized solution
import math

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

sum_gcd = 0
for l in k_range:
    temp = 0
    for m in k_range:
        temp = math.gcd(l, m)
        for n in k_range:
            sum_gcd += math.gcd(n, temp)

print(sum_gcd)
# Original 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):
  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
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):
  if (a==1):
    ans += K*K
    continue
  for b in range(1,K+1):
    t = gcd(a,b)
    if(t==1):
      ans += K
      continue
    for c in range(1,K+1):
      ans += gcd(t,c)
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 a in range(1,K+1):
  for b in range(1,K+1):
    t = gcd(a,b)
    for c in range(1,K+1):
      ans += gcd(t,c)
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):
  if (a==1):
    ans += K*K
    continue
  for b in range(1,K+1):
    t = gcd(a,b)
    if(t==1):
      ans += K
      continue
    for c in range(1,K+1):
      ans += gcd(t,c)
print(ans)
# Original solution
import math
from functools import reduce
def gcd_list(numbers):
  return reduce(math.gcd, numbers)


K = int(eval(input()))
abc_list = []


for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      abc_list.append([a, b, c])

gcds = [gcd_list(x) for x in abc_list]

print((sum(gcds)))

# Optimized solution
import math
from functools import reduce
def gcd_list(numbers):
  return reduce(math.gcd, numbers)

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

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

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

def resolve():
  K = int(eval(input()))
  gcds = sum([ gcd(gcd(x[0], x[1]), x[2]) for x in itertools.product(list(range(1, K+1)), list(range(1, K+1)), list(range(1, K+1))) ])
  print(gcds)

if __name__ == "__main__":
    resolve()

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

def resolve():
  K = int(eval(input()))
  # result = sum([ gcd(gcd(x[0], x[1]), x[2]) for x in itertools.product(range(1, K+1), range(1, K+1), range(1, K+1)) ])
  step1 = [ gcd(x[0], x[1]) for x in product(list(range(1, K+1)), list(range(1, K+1))) ]
  result = sum([ gcd(x[0], x[1]) for x in product(step1, list(range(1, K+1))) ])
  print(result)

if __name__ == "__main__":
    resolve()
# Original solution
from itertools import combinations_with_replacement
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
from itertools import combinations_with_replacement
import math
from functools import reduce

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

sum = 0
k = int(eval(input()))
l = list(range(1,k+1))

for a,b,c in combinations_with_replacement(l, 3):
    ans = gcd(a,b,c)
    if a == b and a == c:
        sum += ans
    elif a == b or b == c or c == a:
        sum += 3 * ans
    else:
        sum += 6 * ans

print(sum)
# Original solution
import math

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


# Optimized solution
import math

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


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


k = int(eval(input()))
l = []
res = 0

for i in range(k):
    for j in range(i, k):
        for m in range(j, k):
            l.append([i+1, j+1, m+1])


for i in range(len(l)):
    # print(l[i])
    if l[i][0] == l[i][1] and l[i][1] == l[i][2]:
        # print("1通り")
        # print(gcd(l[i]))
        res += gcd(l[i])
    elif l[i][0] == l[i][1] or l[i][1] == l[i][2] or l[i][0] == l[i][2]:
        # print("3通り")
        # print(gcd(l[i]))
        res += gcd(l[i])*3
    else:
        # print("6通り")
        # print(gcd(l[i]))
        res += gcd(l[i])*6

print(res)


# Optimized solution
import math
from functools import reduce


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


k = int(eval(input()))
l = []
res = 0

for i in range(1, k+1):
    for j in range(i, k+1):
        for m in range(j, k+1):
            if i == j and j == m:
                res += gcd([i, j, m])
            elif i == j or j == m or i == m:
                res += gcd([i, j, m])*3
            else:
                res += gcd([i, j, m])*6
print(res)
# 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
import math


k = int(eval(input()))
ans = 0
dic = {}
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
# -*- coding: utf-8 -*-
K = int(eval(input()))

# lcm & gcd not math library
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

from functools import reduce
def gcd_multi(num_list):
    return reduce(gcd, num_list)

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:
                dup_num = 1
            elif i == j or j == k:
                dup_num = 3
            else:
                dup_num = 6
            ans += gcd_multi([i, j, k]) * dup_num

print(ans)

# Optimized solution
# -*- coding: utf-8 -*-
K = int(eval(input()))

# lcm & gcd not math library
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
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:
                dup_num = 1
            elif i == j or j == k:
                dup_num = 3
            else:
                dup_num = 6
            ans += gcd(gcd(i, j), k) * dup_num

print(ans)
# Original solution
# -*- coding: utf-8 -*-
K = int(eval(input()))

# lcm & gcd not math library
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
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
# -*- coding: utf-8 -*-
K = int(eval(input()))
 
# lcm & gcd not math library
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
ans = 0
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
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()))
a = 0
for i in range(K):
    for j in range(K):
        for k in range(K):
            a += gcd(i+1,j+1,k+1)
print(a)

# 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]
print((A[K-1]))
# Original 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)


# Optimized solution
import math
K = int(eval(input()))
res = sum([math.gcd(math.gcd(a, b), c) for a in range(1,K+1) for b in range(1,K+1) for c in range(1,K+1)])
print(res)
# Original solution
from math import gcd
from itertools import product


K = int(eval(input()))
l = product(list(range(1, K+1)), repeat=3)

ans = 0
for a, b, c in l:
    ans += gcd(gcd(a, b), c)

print(ans)



# Optimized solution
from math import gcd

K = int(eval(input()))

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

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

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

for a in product(list(range(1,K+1)), repeat=3):
    b += reduce(gcd, a)
print(b)

# Optimized solution
from math import gcd
r = list(range(1, int(eval(input())) + 1))
print((sum(gcd(gcd(i,j),k) for i in r for j in r for k in r)))
# Original solution
import math
K = int(eval(input()))
total = 0
for x in range(1, K+1):
    for y in range(1, K+1):
        for z in range(1, K+1):
            total = total+math.gcd(x, math.gcd(y, z))
print(total)


# Optimized solution
import math
K = int(eval(input()))
total = 0
for x in range(1, K+1):
    for y in range(1, K+1):
        a=math.gcd(x, y)
        for z in range(1, K+1):
            total = total+math.gcd(z, a)
print(total)
# Original solution
#abc162 c
import math
k = int(eval(input()))
def gcds(x,y,z):
    n1 = math.gcd(x,y)
    n2= math.gcd(n1,z)
    return n2
total = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for t in range(1,k+1):
            total += gcds(i,j,t)
print(total)

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

def gcds(x,y,z):
    n1 = math.gcd(x,y)
    n2= math.gcd(n1,z)
    return n2
total =0
for i in range(1,k+1):
    for j in range(1,k+1):
        if math.gcd(i,j) == 1:
            total += k
        else:
            for t in range(1,k+1):
                total += gcds(i,j,t)
print(total)
# Original solution
k = int(eval(input()))

"""
memo = [[-1 for i in range(k+1)] for j in range(k+1)]
def gcd(a, b):
    if b == 0:
        return a
    else:
        if memo[a][b] == -1:
            memo[a][b] = gcd(b, a % b)
        return memo[a][b]
"""

def my_gcd(a, b):
    if a < b: a, b = b, a
    c = a % b
    if c == 0: return b
    while c!=0:
        c = a % b
        a = b
        b = c
    return a

ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        t = my_gcd(a, b)
        for c in range(1, k+1):
            ans += my_gcd(t, c)
print(ans)


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

def gcd(a, b):
    if a < b: a, b = b, a
    c = a % b
    if c == 0: return b
    while c!=0:
        c = a % b
        a = b
        b = c
    return a

ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        t = gcd(a, b)
        if t == 1:
            ans += k
            continue
        for c in range(1, k+1):
            ans += gcd(t, c)
print(ans)
# Original solution
k = int(eval(input()))

def gcd(a, b):
    if a < b: a, b = b, a
    c = a % b
    if c == 0: return b
    while c!=0:
        c = a % b
        a, b = b, c
    return a

ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        t = gcd(a, b)
        if t == 1:
            ans += k
            continue
        for c in range(1, k+1):
            ans += gcd(t, 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):
        t = gcd(a, b)
        if t == 1:
            ans += k
            continue
        for c in range(1, k+1): ans += gcd(t, c)
print(ans)
# Original solution
K = int(eval(input()))

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

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

print(s)


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

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


gcds = [[0 for _ in range(K + 1)] for _ in range(K + 1)]

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

s = 0
for i in range(1, K + 1):
  for j in range(1, K + 1):
    for k in range(1, K + 1):
      s += gcds[gcds[i][j]][k]

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

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

K=int(eval(input()))

ans=K**2+(K-1)*K+(K-1)*(K-1)

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

print(ans)

# Optimized solution
import math


K=int(eval(input()))

ans=0

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

print(ans)
# Original solution
import math


K=int(eval(input()))

ans=0

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

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

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

print(total)  

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

print(total)