CodeEff/ECCO huggingface dataset:
# Original solution
import math
ans=0
k=int(eval(input()))
for i in range(k):
    for j in range(k):
        for z in range(k):
            ans+=math.gcd(z+1,math.gcd(i+1,j+1))
print(ans)

# Optimized solution
import math
ans=0
k=int(eval(input()))
gcdlist=[[math.inf]*(k+1) for i in range(k+1)]
for i in range(1,k+1):
    for j in range(1,k+1):
        gcdlist[i][j]=math.gcd(i,j)
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans+=gcdlist[gcdlist[a][b]][c]
print(ans)
# Original solution
def f(x,y):
    if x%y==0:
        return y
    x,y=y,x%y
    return f(x,y)

def main():
    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+=f(a,f(b,c))
    return sum

print((main()))

# Optimized solution
def f(x,y):
    if x%y==0:
        return y
    x,y=y,x%y
    return f(x,y)

def main():
    K=int(eval(input()))
    sum=0
    for a in range(1,K+1):
        sum+=a
    for a in range(1,K):
        for b in range(a+1,K+1):
            sum+=6*f(a,b)
    for a in range(1,K-1):
        for b in range(a+1,K):
            for c in range(b+1,K+1):
                sum+=f(a,f(b,c))*6
    return sum

print((main()))
# Original solution
import math
K = int(eval(input()))
count = 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(math.gcd(i, j), k)
      count += _gcd
print(count)

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

# Optimized solution
K = int(eval(input()))
def gcd(i, j):
  if i<j:
    tmp=i
    i=j
    j=tmp
  if i%j==0:
    return j
  else:
    return gcd(j, i%j)
count = 0
for i in range(1, K+1):
  for j in range(1, K+1):
    x=gcd(i, j)
    for k in range(1, K+1):
      count += gcd(x, k)
print(count)
# Original solution
#!/usr/bin/env python3
n = int(eval(input()))
ans = 0


def gcd(n, m):
    a, b = n, m
    if a > b:
        a, b = b, a
    while a != 0:
        a, b = b % a, a
    return b


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


# Optimized solution
#!/usr/bin/env python3
n = int(eval(input()))
ans = 0
# gcd_grid = [[0] * 201 for _ in range(201)]


def gcd(n, m):
    """if n <= 200 and m <= 200:
        if gcd_grid[n][m] != 0:
            return gcd_grid[n][m]"""
    a, b = n, m
    if a > b:
        a, b = b, a
    while a != 0:
        a, b = b % a, a
    # gcd_grid[n][m] = b
    # gcd_grid[m][n] = b
    return b


for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        for k in range(j + 1, n + 1):
            ans += 6 * gcd(k, gcd(i, j))
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        ans += 6 * gcd(i, j)
for i in range(n + 1):
    ans += i
print(ans)
# Original solution
K = int(eval(input()))
total = 0

def gdc(x,y):
  if x%y==0:
    return y
  return gdc(y, x%y)

for a in range(K):
  for b in range(K):
    for c in range(K):
      tmp = [a+1,b+1,c+1]
      tmp.sort()
      total += gdc(c+1, gdc(b+1, a+1))
print(total)

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

def gdc(x,y):
  if x%y==0:
    return y
  return gdc(y, x%y)

for a in range(K):
  for b in range(a,K):
    for c in range(b,K):
      if a==b and b==c:
        total += gdc(c+1, gdc(b+1, a+1))
      elif a==b or b==c or a==c:
        total += 3*gdc(c+1, gdc(b+1, a+1))
      else:
        total += 6*gdc(c+1, gdc(b+1, a+1))
print(total)
# Original solution
def gdc(x,y):
  if x%y==0:
    return y
  return gdc(y, x%y)

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

  for a in range(K):
    for b in range(K):
      for c in range(K):
        total += gdc(c+1, gdc(b+1, a+1))
  print(total)
  
if __name__ == '__main__':
    main()

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

def gdc(x,y):
  if x%y==0:
    return y
  return gdc(y, x%y)

for a in range(K):
  for b in range(K):
    tmp = gdc(b+1, a+1)
    for c in range(K):
      total += gdc(c+1, tmp)
print(total)
# Original solution
from itertools import product
import math
n = int(eval(input()))
scores = []
for a, b, c, in list(product(list(range(1, n+1)), repeat=3)):
    gcd_ab = math.gcd(a, b)
    score = math.gcd(gcd_ab, c)
    scores.append(score)
print((sum(scores)))

# Optimized solution
import math
n = int(eval(input()))
scores = 0
for a in range(1, n+1):
    for b in range(1, n+1):
        gcd_ab = math.gcd(a, b)
        for c in range(1, n+1):
            score = math.gcd(gcd_ab, c)
            scores += score
print(scores)
# Original solution
k=int(eval(input()))
z=list(range(1,k+1))
import math
from functools import reduce
sum=0
for i in z:
	for j in z:
		for jj in z:
			sum=sum+reduce(math.gcd,[i,j,jj])
print(sum)

# Optimized solution
from math import gcd
from functools import reduce
 
k=int(eval(input()))
z=list(range(1,k+1))
print((sum([gcd(i,gcd(j,k)) for i in z for j in z for k in z])))
# Original solution
from math import gcd
from functools import reduce
 
k=int(eval(input()))
z=list(range(1,k+1))
print((sum([gcd(i,gcd(j,k)) for i in z for j in z for k in z])))


# Optimized solution
from math import gcd
from functools import reduce
 
k=int(eval(input()))
z=list(range(1,k+1))
print((sum(gcd(i,gcd(j,k)) for i in z for j in z for k in z)))
# Original solution
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans=0
n=int(eval(input()))
for i in range(n):
  for j in range(n):
    for k in range(n):
      if i+1==1 or j+1==1 or k+1==1:
        ans += 1
      else:
        ans+=gcd(i+1, j+1, k+1)
print(ans)


# Optimized solution
from math import gcd
n=int(eval(input()))
l=[gcd(i+1, gcd(j+1, k+1)) for i in range(n) for j in range(n) for k in range(n)]
print((sum(l)))
# 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 i in range(1,K+1):
    ans += i

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

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

for i in range(1, K+1):
    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)
# Original solution
import math
from functools import reduce

def ggcd(*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+=ggcd(i,j,k)

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):
        if math.gcd(i, j)==1:
            sum+=K
        else:
            g=math.gcd(i, j)
            for k in range(1,K+1):
                sum += math.gcd(g,k)
print(sum)
# Original solution
import sys
read = sys.stdin.buffer.read
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(eval(input()))
def MI(): return list(map(int,input().split()))
def MF(): return list(map(float,input().split()))
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
import math


def main():
	
	k=II()
	
	ans=0
	
	li=[0]*(k+1)
	
	for a in range(1,k+1):
		for b in range(1,k+1):
			li[math.gcd(a,b)]+=1
	
	for i in range(1,k+1):
		for c in range(1,k+1):
			ans+=li[i]*math.gcd(i,c)
				
	
	print(ans)





	
if __name__ == "__main__":
	main()


# Optimized solution
import sys
read = sys.stdin.buffer.read
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(eval(input()))
def MI(): return list(map(int,input().split()))
def MF(): return list(map(float,input().split()))
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
import math


def main():
	
	k=II()
	
	ans=0
	
	li=[0]*(k+1)
	
	for a in range(1,k+1):
		for b in range(1,k+1):
			li[math.gcd(a,b)]+=1
	
	for i in range(1,k+1):
		for c in range(1,k+1):
			if li[i]!=0:
				ans+=li[i]*math.gcd(i,c)
				
	
	print(ans)





	
if __name__ == "__main__":
	main()
# 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+= gcd(i,j,k)
            #print(i,j,k)
print(a)

# Optimized solution
K =int(eval(input()))
l = [0, 1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836,194157,207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813,10493367, 10611772,10813692]
print((l[K]))
# Original solution
import math
from functools import reduce


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


K = int(eval(input()))
sumGCD = K * K * K
for a in range(2, K + 1, 1):
    for b in range(2, K + 1, 1):
        for c in range(2, K + 1, 1):
            arr = [a, b, c]
            gcdNum = gcd(*arr)
            # if gcdNum != 1:
            # print(arr)
            # print(gcdNum)
            sumGCD += gcdNum - 1
print(sumGCD)


# Optimized solution
import math

K = int(eval(input()))
sumGCD = K * K * K
for a in range(2, K + 1, 1):
    for b in range(2, K + 1, 1):
        for c in range(2, K + 1, 1):
            arr = [a, b, c]
            gcdNum = math.gcd(math.gcd(a, b), c)
            # if gcdNum != 1:
            # print(arr)
            # print(gcdNum)
            sumGCD += gcdNum - 1
print(sumGCD)
# Original solution
#C
#入力
K=int(eval(input()))+1


#デバッグ用
def pront(*n):
    if debug==1:
        print(n)
        
debug=1#0:本番,1:デバッグ

#処理
import math as m

Z=[ [ [-1 for i in range(K)] for j in range(K)] for l in range(K)]
def C_1(i,j,k):
    xx=[i,j,k]
    xx.sort()
    if Z[xx[0]][xx[1]][xx[2]]!=-1:
        return Z[xx[0]][xx[1]][xx[2]]
    else:
        Z[xx[0]][xx[1]][xx[2]]=m.gcd(m.gcd(xx[0],xx[1]),xx[2])
        return Z[xx[0]][xx[1]][xx[2]]


x=0
for i in range(1,K):
    for j in range(1,K):
        if m.gcd(i,j)==1:
            x+=K-1
        else:
            for k in range(1,K):
                x+=C_1(i,j,k)
print(x)

# Optimized solution
#C
#入力
K=int(eval(input()))


#デバッグ用
def pront(*n):
    if debug==1:
        print(n)
        
debug=1#0:本番,1:デバッグ

#処理
import math as m
Z=[ [-1 for i in range(K+1)] for j in range(K+1)]
def C_1(i,j):
    if Z[i][j]!=-1:
        return Z[i][j]
    else:
        x=m.gcd(i,j)
        Z[i][j]=x
        Z[j][i]=x
        return Z[i][j]

x=0
for i in range(1,K+1):
    for j in range(1,K+1):
        y=C_1(i,j)
        if y==1:
            x+=K
        else:
            for k in range(1,K+1):
                x+=C_1(y,k)
print(x)
# Original solution


import itertools
import math
from functools import reduce

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

K = int(eval(input()))
lis = list(itertools.product(list(range(1, K+1)), repeat=3))

ans=0
for x, y, z in lis:
    ans += gcd(x, y, z)

print(ans)


# Optimized solution


import itertools
import math
from functools import reduce

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

K = int(eval(input()))
lis = list(itertools.combinations_with_replacement(list(range(1, K+1)), 3))

ans=0
for i, j, k in lis:
    if i==j and j==k and i==k:
        ans+=gcd(i, j, k)
    elif i!=j and j!=k and i!=k:
        ans+=6*gcd(i, j, k)
    else:
        ans+=3*gcd(i, j, k)

print(ans)
# Original solution
from itertools import product

#最大公約数
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


k = int(eval(input()))

ans = 0
for i in product(list(range(1, k+1)), repeat=3):
    a, b, c = i
    res = gcd(a, b)
    res = gcd(res, c)
    ans += res
print(ans)

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

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 s in range(1,k+1):
            ans += gcd(i,j,s)
            
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
def GCD(a, b):
    r = a % b
    while(r!=0):
        a = b
        b = r
        r = a % b
    
    return b

def main():
    ans = 0 
    K = int(eval(input()))
    for i in range(1, K+1):
        for j in range(1, K+1):
            if(i < j):
                gcd1 = GCD(j, i)
            else:
                gcd1 = GCD(i, j)
            for k in range(1, K+1):
                ans += GCD(gcd1, k)

    print(ans)



if __name__ == main():
    main()

# Optimized solution
def GCD(a, b):
    r = a % b
    while(r!=0):
        a = b
        b = r
        r = a % b
    
    return b

def main():
    ans = 0 
    K = int(eval(input()))
    for i in range(1, K+1):
        for j in range(1, K+1):

            if(i == 1 or j == 1):
                gcd1 = 1
            elif(i < j):
                gcd1 = GCD(j, i)
            else:
                gcd1 = GCD(i, j)
            for k in range(1, K+1):
                ans += GCD(gcd1, k)

    print(ans)



if __name__ == main():
    main()
# Original solution

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

k = int(eval(input()))
res = 0
for c in range(1,k+1):
    for b in range(1,k+1):
        for a in range(1,k+1):
            # res += gcd(a,b,c)
            gcd1 = math.gcd(a,b)
            gcd2 = math.gcd(gcd1,c)
            res += gcd2
print(res)

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

k = int(eval(input()))
res = 0
for c in range(1,k+1):
    for b in range(1,k+1):
        gcd_cd = math.gcd(c,b)
        for a in range(1,k+1):
            # res += gcd(a,b,c)
            gcd_abc = math.gcd(a,gcd_cd)
            res += gcd_abc
print(res)
# 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 x in range(1,k+1):
            ans +=math.gcd(i,math.gcd(j,x)) 

            
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):
        tmp = math.gcd(i,j)
        for x in range(1,k+1):
            ans +=math.gcd(tmp,x) 

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

print(ans)




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

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

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

N = int(eval(input()))
print((sum([reduce(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)])))

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

N = int(eval(input()))
result = 0
# print(sum([reduce(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)]))
for i in range(1, N+1):
    for j in range(1, N+1):
        tmp = math.gcd(i, j)
        for k in range(1, N+1):
            result += math.gcd(tmp, k)

print(result)
# Original solution

import math

k = int(eval(input()))

cache = {}
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            key = tuple(sorted([a,b,c]))
            x = cache.get(key, math.gcd(math.gcd(a, b), c))
            ans = ans + x
            cache[key] =  x
print(ans)

# Optimized solution
import itertools
import math

k = int(eval(input()))
x = 0
for v in itertools.combinations_with_replacement(list(range(1, k+1)), 3):
    a, b, c = v
    x = x + math.gcd(math.gcd(a,b), c)

y = 0
for v in itertools.combinations(list(range(1, k+1)), 3):
    a, b, c = v
    y = y + math.gcd(math.gcd(a,b), c)

z = k * (1 + k) / 2
print(( int(3 * x  + y * 3  -  2 * z)))
# Original solution
import itertools
import math

k = int(eval(input()))
x = 0
for v in itertools.combinations_with_replacement(list(range(1, k+1)), 3):
    a, b, c = v
    x = x + math.gcd(math.gcd(a,b), c)

y = 0
for v in itertools.combinations(list(range(1, k+1)), 3):
    a, b, c = v
    y = y + math.gcd(math.gcd(a,b), c)

z = k * (1 + k) / 2
print(( int(3 * x  + y * 3  -  2 * z)))

# Optimized solution
import math
 
k = int(eval(input()))
 
cache = {}
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans = ans + cache.get( (a,b,c), 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 x in range(1, k + 1):
        for z in range(1, k + 1):
            ans += math.gcd(i, math.gcd(x, z))
print(ans)

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

ans = 0
for i in range(1, k + 1):
    for x in range(1, k + 1):
        gcdix = gcd(i, x)
        for z in range(1, k + 1):
            ans += gcd(z, gcdix)
print(ans)
# Original solution
from math import gcd
import sys
si = sys.stdin.readline
d = {}


def main():
    k = int(si())
    ans = 0
    for p in range(1, k+1):
        for q in range(1, k+1):
            for r in range(1, k+1):
                if (q, r) in d:
                    t1 = d[(q, r)]
                elif (r, q) in d:
                    t1 = d[(r, q)]
                else:
                    t1 = gcd(q, r)
                    d[(q, r)] = t1
                    d[(r, q)] = t1

                if (p, t1) in d:
                    t2 = d[(p, t1)]
                elif (t1, p) in d:
                    t2 = d[(t1, p)]
                else:
                    t2 = gcd(p, t1)
                    d[(p, t1)] = t2
                    d[(t1, p)] = t2
                ans += t2
    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
from math import gcd
import sys
si = sys.stdin.readline

# def gcd(u, v):
#     if v:
#         return gcd(v, u % v)
#     else:
#         return u


def main():
    k = int(si())
    cnt = 0
    for p in range(1, k+1):
        for q in range(1, k+1):
            for r in range(1, k+1):
                cnt += gcd(p, gcd(q, r))
    print(cnt)


if __name__ == '__main__':
    main()
# Original solution
import math
from functools import reduce

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

ans=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):
      ans+=gcd(a,b,c)
print(ans)


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

from math import gcd

#gcd_sum = [0] * 201
ans = 0

'''
for i in range(1, k+1):
    for j in range(1, k+1):
        gcd_sum[i] += gcd(i,j)
        #print(gcd(i,j))
        #print(gcd_sum[i])
'''
       
for a in range(1,k+1):
    for b in range(1,k+1):
        g = gcd(a,b)
        for c in range(1,k+1):
            ans += gcd(g,c)
        #print(g)
        #print(ans)

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

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


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

K = int(eval(input()))

number = [i for i in range(1, K+1)]
comb = list(product(number, repeat=3))

amount = 0
for a, b, c in comb:
    if a <= b <= c:
        if a == b and b == c:
            amount += a
        elif a == b or b == c:
            count = gcd(a, c)
            amount += count * 3
        else:
            a_k, b_k, c_k = a, b, c
            count = gcd(a, b, c)
            amount += count * 6

print(amount)

# Optimized solution
from itertools import combinations, product
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(eval(input()))

amount = 0
for a in range(1, K+1):
    for b in range(a, K+1):
        for c in range(b, K+1):
            count = gcd(a, b, c)
            if a == b and b == c:
                amount += count
            elif a == b or b == c:
                amount += count * 3
            else:
                amount += count * 6
print(amount)