CodeEff/ECCO huggingface dataset:
# Original solution
def main():
    k = int(eval(input()))
    gcds = list(sorted([gcd(i, j) for i in range(1, k+1) for j in range(1, k+1)]))
    j = 0
    s = list(sorted(list(set(gcds))))
    m = k**2-1
    gcdss = [0]*len(s)
    flag = False
    for i, l in enumerate(s):
        while gcds[j] == l:
            gcdss[i] += 1
            if j == m:
                flag = True
                break
            j += 1
        if flag:
            break
    ans = sum([gcd(i, p)*n for i in range(1, k+1) for p, n in zip(s, gcdss)])
    print(ans)
            
    
def gcd(a, b):
    if a < b:
        a, b = b, a
    if a % b == 0:
        return b
    else:
        return gcd(b, a%b)


if __name__ == "__main__":
    main()


# Optimized solution
def main():
    k = int(eval(input()))
    gcds = []
    for i in range(1, k+1):
        for j in range(1, k+1):
            gcds.append(gcd(i, j))
    ans = {i:0 for i in set(gcds)}
    for i in gcds:
        ans[i] += 1
    out = 0
    for i, v in list(ans.items()):
        for j in range(1, k+1):
            out += gcd(i, j)*v
    print(out)

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

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

def gcd(*numbers):
    return reduce(math.gcd, numbers)
  
k=int(eval(input()))
r=0
for i in range(k):
  for j in range(k):
    for l in range(k):
      r+=gcd(i+1,j+1,l+1)
print(r)


# Optimized solution
import math
  
k=int(eval(input()))
r=0
ls=[]

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


# Optimized solution
from math import gcd
k=int(eval(input()))
re=0
for i in range(1,k+1):
    for j in range(1,k+1):
        v=gcd(i,j)
        for l in range(1,k+1):
            re+=gcd(v,l)
print(re)
# 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 l in range(1,k+1):
            sum_+=reduce(math.gcd,[i,j,l])
print(sum_)


# Optimized solution
l=[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[int(eval(input()))-1]))
# Original solution
sum=0
K=int(eval(input()))+1
r=1
for a in range(1,K):
  for b in range(1,K):
    for c in range(1,K):
      p=a
      q=b
      if p%q==0:
        r=q
      while p%q!=0:
        r=p%q
        p=q
        q=r
      
      p=r
      q=c
      if p%q==0:
        r=q
      while p%q!=0:
        r=p%q
        p=q
        q=r
      sum+=r
print(sum)

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

# Optimized solution

import math

k = int(eval(input()))
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        ab = math.gcd(a, b)
        if ab == 1:
            ans += k
            continue
        for c in range(1, k+1):
            ans += math.gcd(ab,c)

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

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


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

for i in range(1, k+1):
	for j in range(1, k+1):
		for l in range(1, k+1):
			sum += gcd(i, j, l)

print(sum)


# Optimized solution
# def gcd(a, b):
# 	while a != 0 and b != 0:
# 		if a >= b:
# 			remain = a % b
# 			a = remain
# 		else:
# 			remain = b % a
# 			b = remain
# 	if a >= b:
# 		return a
# 	else:
# 		return b 

import math

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

for i in range(1, k+1):
	for j in range(1, i+1):
		for l in range(1, j+1):
			if i == j and j == l:
				sum += i
			elif i == j or j == l:
				a = math.gcd(i, j)
				b = math.gcd(j,l)
				g = math.gcd(a,b)
				sum += g*3

			else:
				a = math.gcd(i, j)
				b = math.gcd(j,l)
				g = math.gcd(a,b)
				sum += g*6

print(sum)
# Original solution
import math

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




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

print(sum)            


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

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

print(sum)        

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

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

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



# Optimized solution
import math
k=int(eval(input()))
d=0
for i in range(1,k+1):
    for j in range(i+1,k+1):
        for l in range(j+1,k+1):
            c=math.gcd(i,j)
            d+=6*(math.gcd(c,l))
for i in range(1,k+1):
    for j in range(i+1,k+1):
        d+=6*(math.gcd(i,j))
for i in range(1,k+1):
    d+=i
print(d)
# Original solution
K = int(eval(input()))
total = 0

def gcd2(a,b): #互除法
  while True:
    mod = a % b
    if mod == 0:
      return b
    a = b
    b = mod

memo = {}
def gcd(a,b,c):
  a,b,c = sorted([a,b,c])
  if (a,b,c) not in memo:
    val = gcd2(gcd2(a,b), c)
    memo[(a,b,c)] = val
    return val
  return memo[(a,b,c)]

for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      g = gcd(a, b, c)
#      print(a,b,c, g)
      total += g

print(total)

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

def gcd2(a,b): #互除法
  while True:
    mod = a % b
    if mod == 0:
      return b
    a = b
    b = mod

memo = {}
def gcd(a,b,c):
  return gcd2(gcd2(a,b),c)
#  a,b,c = sorted([a,b,c])
#  if (a,b,c) not in memo:
#    val = gcd2(gcd2(a,b), c)
#    memo[(a,b,c)] = val
#    return val
#  return memo[(a,b,c)]

for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      g = gcd(a, b, c)
#      print(a,b,c, g)
      total += g

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


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

# table = np.zeros((K,K), dtype="int16")
table = [[0] * K for i in range(K)]

for a in range(K):
    for b in range(a, K):
        tmp = math.gcd(a+1, b+1)
        table[a][b] = tmp
        table[b][a] = tmp

res = 0
for a in range(K):
    for b in range(K):
        for c in range(K):
            res += table[table[a][b]-1][c]
print(res)     

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

res = 0
for a in range(K):
    for b in range(K):
        for c in range(K):
            res += math.gcd(math.gcd(a+1, b+1), c+1)
print(res)
# Original solution
from math import gcd
k = int(eval(input()))
li = []
cnt = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            li.append(gcd(gcd(i, j), gcd(j, l)))
print((sum(li)))

# Optimized solution
from math import gcd
k = int(eval(input()))
li = []
li2 = [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]
cnt = 0
if k < 170:
    for i in range(1, k + 1):
    	for j in range(1, k + 1):
            for l in range(1, k + 1):
        	    li.append(gcd(gcd(i, j), gcd(j, l)))
    print((sum(li)))
else:
    print((li2[k - 170]))
# Original solution
#coding:utf-8

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

def gcd(a,b):
    if a >= b:
        k1, k2 = a, b
    elif a < b:
        k1, k2 = b, a

    r = k1 % k2
    if r != 0:
        return gcd(k2,r)
    elif r == 0:
        return k2

for a in range(1,k+1):

    for b in range(1,k+1):

        f = gcd(a,b)

        for c in range(1,k+1):

            g = gcd(f,c)
            count += g

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

# Optimized solution
#coding:utf-8

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

def gcd(a,b):
    if a >= b:
        k1, k2 = a, b
    elif a < b:
        k1, k2 = b, a

    r = k1 % k2
    if r != 0:
        return gcd(k2,r)
    elif r == 0:
        return k2

for a in range(1,k+1):

    for b in range(1,a+1):

        f = gcd(a,b)

        for c in range(1,b+1):

            g = gcd(f,c)
            
            if a == b and b != c:
                count += g * 3
            elif b == c and c != a:
                count += g * 3
            elif c == a and a != b:
                count += g * 3
            elif a == b and b == c:
                count += g
            else:
                count += g * 6

print(("{}".format(count)))
# 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):
        x = math.gcd(a,b)
        for c in range(1,K+1):
            sum+=math.gcd(x,c)
print(sum)
# Original solution
from functools import lru_cache


@lru_cache(maxsize=None)
def gcd(a, b):
    if a < b:
        a, b = b, a
    if a % b == 0:
        return b
    return gcd(b, a % b)


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


if __name__ == '__main__':
    main()


# Optimized solution
from math import gcd


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


if __name__ == '__main__':
    main()
# Original solution
#!/usr/bin/env python3
import sys
import math
from functools import reduce

def solve(K: int):
    K += 1
    ans = []
    for i in range(1, K):
        for j in range(1, K):
            for k in range(1, K):
                ans.append(gcd(i, gcd(j, k)))
    print((sum(ans)))
    return

def gcd(x: int, y: int):
    """xとyの最大公約数を求める"""
    return gcd(y, x % y) if y else x
    
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()

# Optimized solution
#!/usr/bin/env python3
import sys
import math

def solve(K: int):
    K += 1
    ans = []
    for i in range(1, K):
        for j in range(1, K):
            for k in range(1, K):
                ans.append(math.gcd(i, math.gcd(j, k)))
    print((sum(ans)))
    return

def gcd(x: int, y: int):
    """xとyの最大公約数を求める"""
    return gcd(y, x % y) if y else x
    
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

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

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

def main():
    n = int(eval(input()))
    result = 0
    
    for i in range(1,n+1):
        for j in range(1,n+1):
            for l in range(1,n+1):
                result += gcd(i,j,l)
    
    

    print(result)

if __name__ == "__main__":
    main()

# Optimized solution
import os
from math import gcd


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

if __name__ == "__main__":
    main()
# Original solution
from math import gcd
import itertools
K=int(eval(input()))
res=0
li=[]
for x in itertools.product(list(range(1,K+1)),repeat=2):
    li.append(gcd(x[0],x[1]))
for x,y in itertools.product(list(range(1,K+1)),li):
    res+=gcd(x,y)
print(res)

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

# Optimized solution
import math
k=int(eval(input()))
list=[]
for a in range(1,k+1):
  for b in range(1,k+1):
    t=math.gcd(a,b)
    for c in range(1,k+1):
      list.append(math.gcd(t,c))
print((sum(list)))
# Original solution
k = int(eval(input()))
def gcd(a, b, c):
    gcd1 = 1
    for i in range(2, c+1):
        if a%i == 0 and b%i == 0 and c%i == 0:
            gcd1 = i
    # print(gcd1)
    return gcd1

sum_gcd = 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:
                sum_gcd += gcd(a, b, c)
            elif a == b or b == c or c == a:
                sum_gcd += 3*gcd(a, b, c)
            else:
                sum_gcd += 6*gcd(a, b, c)
print(sum_gcd)


# Optimized solution
k = int(eval(input()))
def gcd(a, b, c):
    gcd1 = 1
    if a%c == 0 and b%c == 0:
        gcd1 = c
    elif a%2 == 0 and b%2 == 0 and c%2 == 0:
        gcd1 = 2
        for i in range(4, c//2+1, 2):
            if a%i == 0 and b%i == 0 and c%i == 0:
                gcd1 = i
    else:
        for i in range(3, c//2+1, 2):
            if a%i == 0 and b%i == 0 and c%i == 0:
                gcd1 = i
    # print(gcd1)
    return gcd1

sum_gcd = 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:
                sum_gcd += gcd(a, b, c)
            elif a == b or b == c or c == a:
                sum_gcd += 3*gcd(a, b, c)
            else:
                sum_gcd += 6*gcd(a, b, c)
print(sum_gcd)
# Original solution
import math
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 += math.gcd(math.gcd(x, y), z)
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

n = int(eval(input()))
sums = 0
sums += n*(n-1)*3 + 1

for k in range(2,n+1):
    for l in range(2,n+1):
        for p in range(2,n+1):
            sums += math.gcd(math.gcd(k,l),p)

print(sums)

# Optimized solution
import math

n = int(eval(input()))
sums = 0
for k in range(1,n+1):
    for l in range(1,n+1):
        a =math.gcd(k,l)
        for p in range(1,n+1):
            sums += math.gcd(a,p)

print(sums)
# Original solution
K = int(eval(input()))

total = 0
# 3つ同じ
for i in range(K):
  total += i+1

# 2つ同じ
#for i in range(0,K-1):
#  total += 6*(K-1-i)*(i+1)

total += 6*(K-1)	# １つが必ず1の場合

for i in range(1,K-1):
  for j in range(i+1,K):
    tmp = 0
    for k in range(1,i+2):
      if (i+1)%k == 0 and (j+1)%k == 0:
        tmp = k
    total += tmp*6

# バラバラ
total += int(6*(K-1)*(K-2)/2)	# １つが必ず1の場合
for i in range(1,K-2):
  for j in range(i+1,K-1):
    for k in range(j+1,K):
      if (j+1)%(i+1) == 0 and (k+1)%(i+1) == 0:
        total += (i+1)*6
      else:
        tmp = 0
        for l in range(1,i+1):
          if (i+1)%l == 0 and (j+1)%l == 0 and (k+1)%l == 0:
            tmp = l
        total += tmp*6
print(total)
  


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

total = 0
for i in range(1,K+1,1):
  for j in range(1,K+1,1):
    tmp1 = i
    tmp2 = j
    while tmp1 % tmp2 != 0:
      tmp = tmp1 % tmp2
      tmp1 = tmp2
      tmp2 = tmp
    for k in range(1,K+1,1):
      tmp1 = k
      tmp3 = tmp2
      while tmp1 % tmp3 != 0:
        tmp = tmp1 % tmp3
        tmp1 = tmp3
        tmp3 = tmp
      total += tmp3
print(total)
# Original solution
import math
n=int(eval(input()))
g=0
for i in range(1,n+1):
    for j in range(1,n+1):
        for h in range(1,n+1):
            d=math.gcd(i,j)
            f=math.gcd(h,d)
            g=g+f
print(g)

# Optimized solution

import math
n=int(eval(input()))
g=0

for i in range(1,n+1):
    for j in range(1,n+1):
        d=math.gcd(i,j)
        for h in range(1,n+1):
            f=math.gcd(h,d)
            g=g+f
print(g)
# Original solution
import math
K = int(eval(input()))
p = 0
for a in range(K):
  for b in range(K):
    for c in range(K):
      p += math.gcd(math.gcd(a+1, b+1),c+1)
print(p)


# Optimized solution
import math
K = int(eval(input()))
p = int(K*(K+1)/2)
for a in range(K):
    for b in range(a+1, K):
        g = math.gcd(a+1, b+1)
        p += 6*g
        for c in range(b+1, K):
                p += 6*math.gcd(g, c+1)
print(p)
# Original solution
K=int(eval(input()))

from math import gcd

ans=0
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(ans)

            

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

def gcd(x,y):
    if x<y:
        temp=x
        x=y
        y=temp
    if x%y==0:
        return y
    else:
        nx=y
        ny=x%y
        return gcd(nx,ny)
ans=0
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(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)

number = int(eval(input()))
sumx = 0
for i in range(1,number+1):
  for j in range(1,number+1):
    for k in range(1,number+1):
#      print("i",i)
#      print("j",j)
#      print("k",k)
#      print(gcd(i,j,k))
      sumx = sumx + gcd(i, j, k)

print (sumx)
  

# Optimized solution
import math

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

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

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

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

# 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
import itertools
import math

k = int(eval(input()))
ans = 0
t = 0
for x, y, z in itertools.product(list(range(1, k+1)), list(range(1, k+1)),list(range(1, k+1))):
    ans = math.gcd(x, y)
    ans = math.gcd(ans, z)
    t+=ans

print(t)

# Optimized solution
from math import gcd
k = int(eval(input()))
ans = 0
t = 0
for i1 in range(1, k+1):
    for i2 in range(1, k+1):
        for i3 in range(1, k+1):
            t += gcd(gcd(i1, i2), i3)
print(t)
# Original solution
import math
k = int(eval(input()))
t = 0
for i1 in range(1, k+1):
    for i2 in range(1, k+1):
        for i3 in range(1, k+1):
            t+=math.gcd(math.gcd(i1, i2), i3)
print(t)

# Optimized solution
from math import gcd
k = int(eval(input()))
t = 0
for i1 in range(1, k+1):
    for i2 in range(1, k+1):
        for i3 in range(1, k+1):
            t+=gcd(gcd(i1, i2), i3)
print(t)
# Original solution
def gcd(a,b):
    c = 0
    if b > a:
        a,b = b,a
    while a % b != 0:
        c = b
        b = a % b
        a = c
    return b
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):
            count += gcd(gcd(i,j),k)
print(count)

# Optimized solution
import math
K = int(eval(input()))
count = 0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(1,K+1):
            if i != j:
                count += 2 * math.gcd(math.gcd(i,j),k)
            else:
                count += math.gcd(math.gcd(i,j),k)
print(count)
# Original solution
from functools import reduce

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

def gcdArr(a):
    return reduce(gcd, a)

n = int(eval(input()))
ret = 0
for a in range(1, n + 1):
    for b in range(1, n + 1):
        for c in range(1, n + 1):
            ret += gcdArr((a, b, c))
print(ret)

# Optimized solution
from functools import reduce

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

def gcdArr(a):
    return reduce(gcd, a)

n = int(eval(input()))
ret = 0
for a in range(1, n + 1):
    for b in range(1, n + 1):
        gcd_ = gcd(a, b)
        if gcd_ == 1:
            ret += n
            continue
        for c in range(1, n + 1):
            ret += gcd(gcd_, c)
print(ret)