CodeEff/ECCO huggingface dataset:
# 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(i+1, K):
        for k in range(j+1, K+1):
            ans += gcd(i, j, k)*6
for i in range(1, K):
    for j in range(i+1, K+1):
        ans += math.gcd(i, j)*6
for i in range(1, K+1):
    ans += i
    
print(ans)

# Optimized solution
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]
n = int(eval(input()))
print((a[n-1]))
# Original solution
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def gcdlist(*l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a

N = int(eval(input()))

I = list(range(1, N+1))
J = list(range(1, N+1))
K = list(range(1, N+1))

combinations = [(i, j, k)
                for i in I
                for j in J
                for k in K]

count = 0

for i, j, k in combinations:
    count = count + gcdlist(i, j, k)

print(count)

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

from math import gcd

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

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

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

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

  ans = 0

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

  print(ans)



if __name__ == "__main__":
  main()

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

def gcd3(a,b,c):
  d = gcd(a,b)
  ans = gcd(d,c)
  return ans

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

  ans = 0

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

  print(ans)

if __name__ == "__main__":
  main()
# Original solution
from math import gcd
K = int(eval(input()))
sum = 0
for a in range(K):
    for b in range(K):
        for c in range(K):
            sum += gcd(gcd(a + 1, b + 1), c + 1)
print(sum)


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

K=int(eval(input()))
s=0
for a,b,c in itertools.product(list(range(1,K+1)),list(range(1,K+1)),list(range(1,K+1))):
    	s+=math.gcd(math.gcd(a,b),c)
print(s)

# Optimized solution
import math
from itertools import product

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

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

print(ans)


# Optimized solution
import math

n = int(eval(input()))

ans = 0

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

print(ans)
# Original solution
from math import gcd
N = int(eval(input()))
ans = 0
for i in range(1,N+1):
  for k in range(1,N+1):
    for l in range(1,N+1):
      if i == k and k == l:
        tmp = i
      elif i==k:
        tmp = gcd(k,l)
      elif k==l:
        tmp = gcd(l,i)
      elif l==i:
        tmp = gcd(i,k)

      else:
        a = l 
        b = k
        c = i
        d = gcd(a,b)
        e = gcd(b,c)
        tmp = gcd(d,e)
      ans += tmp

print(ans)


# Optimized solution
from math import gcd
N = int(eval(input()))
ans = sum([gcd(gcd(i,j),k) for i in range(1,N+1) for j in range(1,N+1) for k in range(1,N+1)])
print(ans)
# Original solution
import math
ans = 0
N = int(eval(input()))
for i in range(N):
    for j in range(N):
        for k in range(N):
            ans += math.gcd(math.gcd(i+1,j+1),math.gcd(j+1,k+1))
print(ans)

# Optimized solution
import math
ans = 0
N = int(eval(input()))
if N <= 5:
  for i in range(N):
    for j in range(N):
        for k in range(N):
            ans += math.gcd(math.gcd(i+1,j+1),math.gcd(j+1,k+1))
else:
    for i in range(N):
        ans += i+1
    for i in range(N-1):
        for j in range(i+1,N):
            ans += 6*math.gcd(i+1,j+1)
    for i in range(N-2):
        for j in range(i+1,N-1):
            for k in range(j+1,N):
                ans += 6*math.gcd(math.gcd(i+1,j+1),math.gcd(j+1,k+1))
print(ans)
# Original solution
import math
ans = 0
N = int(eval(input()))
if N <= 5:
  for i in range(N):
    for j in range(N):
        for k in range(N):
            ans += math.gcd(math.gcd(i+1,j+1),math.gcd(j+1,k+1))
else:
    for i in range(N):
        ans += i+1
    for i in range(N-1):
        for j in range(i+1,N):
            ans += 6*math.gcd(i+1,j+1)
    for i in range(N-2):
        for j in range(i+1,N-1):
            for k in range(j+1,N):
                ans += 6*math.gcd(math.gcd(i+1,j+1),math.gcd(j+1,k+1))
print(ans)

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

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

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

def gcd2(x,y,z):
    return math.gcd(math.gcd(x,y),z)

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

print(sum)





# Optimized solution
import math
import fractions

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

def gcd2(x,y,z):
    return math.gcd(math.gcd(x,y),z)

for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            if (i == j == k):
                sum += gcd2(i,j,k)
            elif i != j and j != k:
                sum += gcd2(i,j,k)*6
            else:
                sum += gcd2(i,j,k)*3



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

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

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

def gcd(numbers):
    return reduce(lambda x,y: math.gcd(x,y),numbers)

def comb(K):
    return itertools.combinations_with_replacement(list(range(1,K+1)),3)

def main():
    k = int(eval(input()))
    if k == 1:
        print((1))
        return
    elif k == 2:
        print((9))
        return

    final = 0
    comb_list = list(comb(k))

    for i in comb_list:
        if len(set(i)) == 1:
            final += 1*gcd(i)
        elif len(set(i)) == 2:
            final += 3*gcd(i)
        else:
            final += math.factorial(3)*gcd(i)

    #print(comb_list)
    print(final)
main()


# Optimized solution
import math

def main():

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

    #because gcd can only appear in this range
    count = [0]*201
    
    for i in r:
        for j in r:
            count[math.gcd(i,j)] += 1
    
    final = 0
    
    for i in range(1,201):
        if count[i] > 0:
            for j in r:
                final += count[i]*math.gcd(i,j)
    
    print(final)


main()
# Original solution
import math
from functools import reduce

K = int(eval(input()))

memo = {}
def gcd(a, b):
  key = frozenset((a,b))
  if key in memo:
    return memo[key]
  memo[key] = math.gcd(a, b)
  return memo[key]
ans = 0
for i in range(1, K+1):
  for j in range(1, K+1):
    for k in range(1, K+1):
      ans += reduce(gcd, [i, j, k])
print(ans)

# Optimized solution
import math
from collections import Counter

K = int(eval(input()))

memo = {frozenset((i, j)): math.gcd(i, j) 
        for i in range(1, K+1) for j in range(i, K+1)}

counter = Counter([memo[frozenset((i, j))] 
                   for i in range(1, K+1) for j in range(1, K+1)])

total = 0
for i in range(1, K+1):
  for value, count in list(counter.items()):
    total += memo[frozenset((i, value))] * count
    
print(total)
# Original solution
# C
k = int(eval(input()))

def gcd(x, y): 
    while(y): 
        x, y = y, x % y
    return x 

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

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

# Optimized solution
import math
A = int(eval(input()))
def gcd(A):
    total = 0
    for i in range(1,A+1):
        for j in range(1,A+1):
            B = math.gcd(i,j)
            for k in range(1,A+1):
                total += math.gcd(B,k)
    return total
print((gcd(A)))
# Original solution
from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin

d = dict()


def gcd(a, b):
    if (a, b) in d:
        return d[(a, b)]
    if b == 0:
        return a
    else:
        res = gcd(b, a % b)
        d[(a, b)] = res
        return res
    return


def gcd_3(a, b, c):
    return gcd(gcd(a, b), c)


def main():
    res = 0
    n = int(eval(input()))
    for a in range(1, n+1):
        for b in range(1, n+1):
            for c in range(1, n+1):
                res += gcd_3(a, b, c)
    print(res)


def input(): return stdin.readline().rstrip()


main()


# Optimized solution
from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin

d = dict()


def gcd(a, b):
    if (a, b) in d:
        return d[(a, b)]
    if b == 0:
        return a
    else:
        res = gcd(b, a % b)
        d[(a, b)] = res
        return res
    return


def gcd_3(a, b, c):
    return gcd(gcd(a, b), c)


def main():
    res = 0
    n = int(eval(input()))
    for a in range(1, n+1):
        for b in range(1, n+1):
            m = gcd(a, b)
            if m == 1:
                res += 1*n
            else:
                for c in range(1, n+1):
                    res += gcd(m, c)
    print(res)


def input(): return stdin.readline().rstrip()


main()
# Original 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):
            d = gcd(a,b)
            total += gcd(d,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)
# Original solution
import math

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

print(res)

# Optimized solution
from math import gcd

k = int(eval(input()))
res = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for m in range(1, k+1):
            res += gcd(gcd(i, j), m)

print(res)
# Original solution
from math import gcd

K = int(eval(input()))
res = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      s = gcd(a,b)
      res += gcd(s,c)

print(res)

# Optimized solution
from math import gcd

K = int(eval(input()))
res = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      res += gcd(gcd(a,b),c)

print(res)
# Original solution
import math
from functools import reduce
import itertools
K = int(eval(input()))
def gcd(*numbers):
    return reduce(math.gcd, numbers)
count = 0
for i, j , k in itertools.product(list(range(K)), list(range(K)), list(range(K))):
  count += gcd(i+1,j+1,k+1)
      
print(count)

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

# Optimized solution
import math
 
K = int(eval(input()))
 
lists = []
for i in range(1, K + 1):
    for j in range(1, K + 1):
        mid = math.gcd(i, j)
        for k in range(1, K + 1):
            lists.append(math.gcd(mid, k))
 
print((sum(lists)))
# Original solution
K = int(eval(input()))

def gcd(n,m,l):
    A = [ n , m , l ]
    A = sorted(A)
    
    while A[0] % A[2] != 0 :
        A[0] , A[2] = A[2] , A[0] % A[2]

    while A[1] % A[2] != 0 :
        A[1] , A[2] = A[2] , A[1] % A[2]
    
    return A[2]
  
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(a, b, c)

print ( S )
    



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

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

print ( S )
# Original solution
from sys import stdin
import math
from functools import reduce

def main():

    input = stdin.readline

    K = int(eval(input()))

    ans_sum = 0

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

                sum_type = len(set(check))
                if sum_type == 1:
                    ans_sum += gcd(i,j,k)
                elif sum_type == 2:
                    ans_sum += gcd(i,j,k) * 3
                else:
                    ans_sum += gcd(i,j,k) * 6

    print(ans_sum)


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


if __name__ == "__main__":
    main()

# Optimized 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)
# 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):
            x = math.gcd(i, j)
            ans += math.gcd(x, k)
print(ans)

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

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

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

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

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

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

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

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

# Optimized solution

import math

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

for i in range(1,n+1):
    for j in range(1,n+1):
        t = math.gcd(i,j)
        for k in range(1,n+1):
            m = math.gcd(t,k)
            count += m
print(count)
# Original solution
import math
from functools import reduce
num = int(eval(input()))
ans = 0
for i in range(1, num + 1):
    for j in range(1, num + 1):
        for k in range(1, num + 1):
            ans += math.gcd(math.gcd(i, j), k)
print(ans)

# Optimized solution
import math
num = int(eval(input()))
ans = 0
for i in range(1, num + 1):
    for j in range(1, num + 1):
        tmp = math.gcd(i, j)
        for k in range(1, num + 1):
            ans += math.gcd(tmp, k)

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


K = int(eval(input()))

L = [[[0] * K for _ in range(K)] for _ in range(K)]
ans = 0

for a in range(1, K+1):
    for b in range(1, K+1):
        d = gcd(a, b)
        for c in range(1, K+1):
            x, y, z = sorted([a, b, c])
            x -= 1
            y -= 1
            z -= 1
            if L[x][y][z] != 0:
                ans += L[x][y][z]
            else:
                t = gcd(d, c)
                ans += t
                L[x][y][z] = t

print(ans)

# Optimized solution
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


K = int(eval(input()))

L = [[0] * (K+1) for _ in range(K+1)]
ans = 0

for a in range(1, K+1):
    for b in range(1, K+1):
        x, y = sorted([a, b])
        if L[x][y] == 0:
            d = gcd(a, b)
            L[x][y] = d
        else:
            d = L[x][y]
        for c in range(1, K+1):
            x, y = sorted([d, c])
            if L[x][y] == 0:
                t = gcd(d, c)
                L[x][y] = t
                ans += t
            else:
                ans += L[x][y]


print(ans)
# Original 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):
      gcd = math.gcd(k, math.gcd(i, j))
      sum = sum + gcd
print(sum)

# Optimized solution
from math import gcd

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

for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            sum += gcd(c, gcd(a, b))
print(sum)
# Original solution
import math
import itertools

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) :
            y=math.gcd(i,k)
            z=math.gcd(x,y)
            ans+=z

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
mem = {}
def gcd(a, b):
    global mem
    if (a, b) not in mem:
        mem[(a, b)] = a if b == 0 else gcd(b, a%b)
    return mem[(a, b)]

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

# Optimized solution
import time
mem = {}
def gcd(a, b):
    global mem
    if (a, b) not in mem and (b, a) not in mem:
        mem[(a, b)] = a if b == 0 else gcd(b, a%b)
        mem[(b, a)] = mem[(a, b)]
    return mem[(a, b)]

K = int(eval(input()))
res = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        gcd(i, j)
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            res += mem[(mem[i, j], k)]
print(res)
# Original solution
from math import gcd
K = int(eval(input()))
res = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            res += gcd(gcd(i, j), k)
print(res)

# Optimized solution
import time
def gcd(a, b):
    return a if b == 0 else gcd(b, a%b)

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

k = int(eval(input()))

k += 1
ans = 0

for a in range(1, k):
    for b in range(1, k):
        for c in range(1, k):
            ab = math.gcd(a, b)
            bc = math.gcd(b, c)
            abc = math.gcd(ab, bc)

            ans += abc

print(ans)


# Optimized solution
import math

k = int(eval(input()))

k += 1
ans = 0

ab = []

for a in range(1, k):
    for b in range(1, k):
       ab.append(math.gcd(a, b))

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

print(ans)
# Original solution
import math
from functools import reduce
 
N=int(eval(input()))
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
A = 0
for i in range(1,N+1):
  for j in range(1,N+1):
    for k in range(1,N+1):
      A += math.gcd(math.gcd(i,j),k)

print(A)

# Optimized solution
import math
 
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 += math.gcd(math.gcd(i,j),k)

print(A)
# Original solution
import sys
from math import gcd

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    k = int(rl())
    ans = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                d = gcd(a, b)
                ans += gcd(c, d)
    print(ans)


if __name__ == '__main__':
    solve()


# Optimized solution
import sys
from math import gcd

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    k = int(rl())
    ans = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            d = gcd(a, b)
            for c in range(1, k + 1):
                ans += gcd(c, d)
    print(ans)


if __name__ == '__main__':
    solve()