CodeEff/ECCO huggingface dataset:
# Original solution
import itertools 
import math
from functools import reduce

num = int(eval(input()))
a_list = [i for i in range(1,num+1)]
comb_list = list(itertools.product(a_list, repeat=3))

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

print((sum([gcd_list(x) for x in comb_list])))

# Optimized solution
import itertools 
import math
from functools import reduce


num = int(eval(input()))

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

if num<=2:
    a_list = [i for i in range(1,num+1)]
    comb_list = list(itertools.product(a_list, repeat=3))
    print((sum([gcd_list(x) for x in comb_list])))

else:
    a_list = [i for i in range(1,num+1)]
    comb_list = list(itertools.combinations_with_replacement(a_list, 3))
    test = sum([gcd_list(x) for x in comb_list])*3

    comb_list_dup = [[i, i, i] for i in a_list]
    duplica = sum([gcd_list(x) for x in comb_list_dup])*2

    comb_list_unique = list(itertools.combinations(a_list, 3))
    unique = sum([gcd_list(x) for x in comb_list_unique])*3
    print((test-duplica+unique))
# Original solution
import math
from functools import reduce

K = int(eval(input()))
gcd_v = {}
def gcd(numbers):
    tuple_n = tuple(sorted(numbers))
    try:
        return gcd_v[tuple_n]
    except:
        gcd_v[tuple_n] = reduce(math.gcd, numbers)
        return gcd_v[tuple_n]

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):
        res = reduce(math.gcd, numbers)
        n = len(set(numbers))
        if n == 1:
            return res
        elif n == 2:
            return res * 3
        else:
            return res * 6

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

print(ans)
# Original solution
k = int(eval(input()))

s = 0
for i1 in range(1, k+1):
    for i2 in range(1, i1+1):
        x1, x2 = i1, i2
        while x2 != 0:
            x1, x2 = x2, x1 % x2
        gcd1 = x1
        s2 = i1 == i2
        for i3 in range(i1, k+1):
            x1, x2 = gcd1, i3
            while x2 != 0:
                x1, x2 = x2, x1 % x2
            gcd2 = x1

            s3 = i2 == i3 or i1 == i3
            if s2 and s3:
                s = s + gcd2
            elif s2 or s3:
                s = s + gcd2*3
            else:
                s = s + gcd2*6
print(s)


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

s = 0
# 3つ違う
for i1 in range(1, k+1):
    s = s + i1
    for i2 in range(1, i1):
        x1, x2 = i1, i2
        while x2 != 0:
            x1, x2 = x2, x1 % x2
        gcd1 = x1
        s = s + gcd1 * 6
        for i3 in range(i1+1, k+1):
            x1, x2 = gcd1, i3
            while x2 != 0:
                x1, x2 = x2, x1 % x2
            gcd2 = x1
            s = s + gcd2 * 6

print(s)
# 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(k, math.gcd(i,j))
print(ans)

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

def better_gcd(a,b,c):
    tup = set((a,b,c))
    kinds = len(tup)
    if kinds == 3:
        return math.gcd(a, math.gcd(b, c)) * 6
    elif kinds == 2:
        return math.gcd(*tup) * 3
    else:
        return a

ans = 0
cands = list(itertools.combinations_with_replacement(list(range(1,K+1)), 3))
for c in cands:
    ans += better_gcd(*c)
print(ans)
# Original solution
a=int(eval(input()))
b=0
c=1
import math
from functools import reduce

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

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

for i in range(1,a+1):
    for j in range(1,a+1):
        
        for z in range(1,a+1):
            

            b+=gcd(i,j,z)


print(b)

# Optimized solution
import math
n=int(eval(input()))
g=0
for i in range(1,1+n):
    for j in range(1,1+n):
        d=math.gcd(i,j)
        for z in range(1,n+1):
            f=math.gcd(z,d)
            g+=f
print(g)
# Original solution

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

a = int(eval(input()))

ans =0
for n in range(a):
    for l in range(a):
        for m in range(a):
            ans += gcd_tri(n+1,l+1,m+1)
print(ans)

# Optimized solution
import math
a = int(eval(input()))
lis =[]
ans = 0
for x in range(1,a+1):
    for y in range(1, a+1):
        lis.append(math.gcd(x,y))
for z in range(1, a+1):
    for l in lis:
        ans += math.gcd(z,l)
print(ans)
# Original solution
import itertools
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd,numbers)
K=int(eval(input()))
ans=0
x=[]
for i in range(1,K+1):
  for j in range(1,K+1):
    x.append(math.gcd(i,j))
for i in x:
  for j in range(1,K+1):
    ans+=gcd(i,j)
print(ans)

# Optimized solution
import itertools
import math
from functools import reduce
K=int(eval(input()))
ans=0
for i in range(1,K+1):
  for j in range(1,K+1):
    t=math.gcd(i,j)
    for k in range(1,K+1):
      ans+=math.gcd(t,k)
print(ans)
# 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 x in range(1,k+1):
            ans+=gcd_list([i,j,x])
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):
        p=gcd(i,j)
        for x in range(1,k+1):
            ans+=gcd(x,p)
print(ans)
# Original solution
import math

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

def gcd(a,b,c):
    d = math.gcd(a,b)
    e = math.gcd(d,c)
    return e

for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            y = gcd(a,b,c)
            A += y

print(A)





# Optimized solution
import math

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

for a in range(1,k+1):
    for b in range(1,k+1):
        p = math.gcd(a,b)
        for c in range(1,k+1):
            y = math.gcd(p,c)
            A += y

print(A)
# Original solution
K = int(eval(input()))
N = 3
def common_divisor(num1,num2):
    max_n = max(num1,num2)
    min_n = min(num1,num2)
    temp = max_n%min_n
    while True:
        if temp:
            max_n = min_n
            min_n = temp
            temp = max_n%min_n
        else:
            return min_n

sum = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        temp = common_divisor(i,j)
        for m in range(1,K+1):
            sum = sum+common_divisor(m,temp)
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):
        temp = math.gcd(i,j)
        for m in range(1,K+1):
            sum = sum+math.gcd(m,temp)
print(sum)
# Original solution
def gcd(a,b):
    if not b:
        return a
    else:
        return gcd(b, a%b)

n = int(eval(input()))

ans = 0

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

print(ans)

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

n = int(eval(input()))

ans = 0

for i in range(1,n-1):
    for j in range(i+1, n):
        tmp = gcd(i,j)
        for k in range(j+1, n + 1):
            ans += gcd(tmp,k) * 6

for i in range(1,n):
    for j in range(i+1,n+1):
        ans += 6*gcd(i,j)
# print(ans)
ans += (n*(n+1))//2

print(ans)
# Original solution
import math
k = int(eval(input()))
a = list(range(1,k+1))
ans = 0
for x in a:
  for y in a:
    for z in a:
      ans += math.gcd(math.gcd(x,y),z)
print(ans)

# Optimized solution
import math
k = int(eval(input()))
ans = 0
for x in range(1,k+1):
  for y in range(1,k+1):
    hoge = math.gcd(x,y)
    for z in range(1,k+1):
      ans += math.gcd(hoge,z)
print(ans)
# Original solution
import sys
input = sys.stdin.readline

import itertools

import math

from functools import reduce

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

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

    num_li = list(range(1, k+1))

    ans = 0

    old_dict = {}

    for l in itertools.product(num_li, repeat=3):

        str_l = str(sorted(l))

        if str_l in old_dict:
            ans += old_dict[str_l]
        else:
            num = gcd(l[0], l[1], l[2])
            old_dict[str_l] = num
            ans += num

    print(ans)


if __name__ == '__main__':
    main()


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

import math

def main():
    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(math.gcd(i,j),l)

    print(ans)


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

k = int(eval(input()))

ans = 0

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

print(ans)


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

import math

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

    ans = 0

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

    print(ans)


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)


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

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

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

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

# Optimized solution
import math
K=int(eval(input()))
N=0
k=K*K
d1=[0]*int(k)
i=0
j=0
for b in range(K):
    for c in range(K):
        d1[i]=math.gcd((c+1),(b+1))
        i+=1
for a in range(K):
    for x in d1:
        N+=math.gcd(x,(a+1))
print(N)
# Original 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)

# 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):
        x=gcd(i,j)
        for l in range(1,k+1):
            ans+=gcd(x,l)
print(ans)
# Original solution
def main():
    K = int(eval(input()))

    su = 0
    # for a in range(1, K+1):
    #     for b in range(1, a+1):
    #         for c in range(1, b+1):
    #             tmp = dgcd(a, b, c)
    #             if a == b and b == c:
    #                 pass
    #             elif a == b or b == c or a == c:
    #                 tmp *= 3
    #             else:
    #                 tmp *= 6
    #             su += tmp
    # print(su)
    for a in range(1, K+1):
        for b in range(1, K+1):
            for c in range(1, K+1):
                tmp = dgcd(a, b, c)

                su += tmp
    print(su)


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


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


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    K = int(eval(input()))

    su = 0
    for a in range(1, K+1):
        for b in range(1, a+1):
            for c in range(1, b+1):
                tmp = dgcd(a, b, c)
                if a == b and b == c:
                    tmp *= 1
                elif a == b or b == c or a == c:
                    tmp *= 3
                else:
                    tmp *= 6

                su += tmp
    print(su)


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


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


if __name__ == '__main__':
    main()
# Original solution
K = int(eval(input()))
sum = 0
class gcd:
    def __init__(self,a,b,c):
        self.a=a
        self.b=b
        self.c=c
        
    def gcds(self):
        if self.a>self.b:
            x=self.a
            y=self.b
        else:
            x=self.b
            y=self.a
            
        while x % y!=0:
            tem_y = y
            y = x % y 
            x = tem_y
       
        gcd_1 = y
        
        if gcd_1>self.c:
            x=gcd_1
            y=self.c
        else:
            x=self.c
            y=gcd_1
            
        while x % y!=0:
            tem_y = y
            y = x % y 
            x = tem_y
       
        return int(y)

for i in range(K):
    for j in range(K):
        for l in range(K):
            sum = sum + gcd(i+1,j+1,l+1).gcds()
            
print(sum)

# Optimized solution
K = int(eval(input()))
sum = 0
class gcd:
    def __init__(self,a,b,c):
        self.a=a
        self.b=b
        self.c=c
        
    def gcds(self):
        if self.a>self.b:
            x=self.a
            y=self.b
        else:
            x=self.b
            y=self.a
            
        while x % y!=0:
            tem_y = y
            y = x % y 
            x = tem_y
       
        gcd_1 = y
        
        if gcd_1>self.c:
            x=gcd_1
            y=self.c
        else:
            x=self.c
            y=gcd_1
            
        while x % y!=0:
            tem_y = y
            y = x % y 
            x = tem_y
       
        return int(y)

for i in range(1,K+1):
    for j in range(i,K+1):
        for l in range(j,K+1):
            if i==j and j==l:
                sum = sum + gcd(i,j,l).gcds()
            elif i != j and j==l:
                sum = sum + gcd(i,j,l).gcds()*3
            elif i==j and j!= l:
                sum = sum + gcd(i,j,l).gcds()*3
            elif i!=j and j!=l:
                sum = sum + gcd(i,j,l).gcds()*6         
            
print(sum)
# Original solution
N = int(eval(input()))
sum=0
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
from itertools import product
pools = product(list(range(N)),list(range(N)),list(range(N)))
for i, j ,k in pools:
  sum =sum + gcd(i+1, j+1, k+1)
print(sum)

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

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

# 組み合わせの数
# a, b, cが同じは1pattern
# a, b, cのうち、２つが同じパターンは３
# a, b, cのうち、全て異なるパターンは6
# つまり、３つの数の組み合わせの数を求め、各パターン倍すればよい

# タプルで集合を作成する
# st = set()
# # # for a in range(1, K+1):
# # #     for b in range(1, K+1):
# # #         for c in range(1, K+1):
# # #             sort_abc = sorted([a, b, c])
# # #             st.add(tuple(sort_abc))
# # # # print(st)
# # # for s in st:
# # #     if s[0] == s[1] == s[2]:
# # #         summ += reduce(math.gcd, s)
# # #         # print(0, s)
# # #     elif s[0] == s[1] or s[0] == s[2] or s[1] == s[2]:
# # #         summ += 3*reduce(math.gcd, s)
# # #         # print(1, s)
# # #     else:
# # #         summ += 6*reduce(math.gcd, s)
# # #         # print(2, s)
# # # print(summ)

for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            summ += reduce(math.gcd, [a, b, c])
print(summ)


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

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

print(ans)
# Original solution
import math
import itertools
k = int(eval(input()))
t = list([list(x) for x in itertools.product([i+1 for i in range(k)],repeat=3)])
ans = 0
for i in range(len(t)):
    ans += math.gcd(math.gcd(t[i][0],t[i][1]),t[i][2])
print(ans)

# Optimized solution
import math
import itertools
k = int(eval(input()))
t = list([list(x) for x in itertools.product([i+1 for i in range(k)],repeat=2)])
ans = 0
for i in range(len(t)):
    cu = math.gcd(t[i][0],t[i][1])
    for j in range(1,k+1):
        ans += math.gcd(j,cu)
print(ans)
# Original solution
import math
K = int(eval(input()))
rst = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        tmp = math.gcd(i, j)
        for k in range(1, K + 1):
            rst += math.gcd(tmp, k)
print(rst)


# Optimized solution
import math

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

for i in range(1, K + 1):
  for j in range(1, K + 1):
    tmp = math.gcd(i, j)
    for k in range(1, K + 1):
      sum += math.gcd(tmp, k)
      
print(sum)
# Original solution
import math
from functools import reduce
def gcd(*numbers):
  return reduce(math.gcd,numbers)
K=int(eval(input()))
a=list(range(1,K+1))
b=list(range(1,K+1))
c=list(range(1,K+1))
ans=0
for j in a:
  for k in b:
    for l in c:
      ans+=gcd(j,k,l)
print(ans)

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

K = int(eval(input()))

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

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

# print(p_list)

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

sum = 0

for p in p_list:
    sum += gcd_list(p)

print(sum)

# Optimized solution
import math
from functools import reduce

K = int(eval(input()))

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

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(a, b, c)

print(sum)
# Original solution
import math
from functools import reduce
def gcd_list(numbers):
  return reduce(math.gcd,numbers)
count=0
n=int(eval(input()))+1
for i in range(1,n):
  for j in range(1,n):
    for k in range(1,n):
      val=gcd_list([i,j,k])
      count+=val
print(count)

# Optimized solution
import math
 
n=int(eval(input()))+1
ans=0
for i in range(1,n):
  for j in range(i,n):
    for k in range(j,n):
      if i==j and i==k:
        buff=1
      elif i==j:
        buff=3
      elif j==k:
        buff=3
      else:
        buff=6
      g1=math.gcd(i,j)
      g=math.gcd(k,g1)
      ans+=g*buff
print(ans)
# Original solution
import math
k = int(eval(input()))
s = 0
a = []
b = []
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            p = [i,j,l]
            p.sort()
            if (p in a):
                s += b[a.index(p)]
            else:
                a.append(p)
                t = math.gcd(i,j)
                q = math.gcd(t,l)
                s += q
                b.append(q)
print(s)


# Optimized solution
import math
k = int(eval(input()))
s = 0
b = []
for i in range(1,k+1):
    for j in range(i,k+1):
        for l in range(j,k+1):
            p = len(set([i,j,l]))
            if p ==1:
                t = math.gcd(i,j)
                q = math.gcd(t,l)
                s += q
                b.append(q)
            elif p ==2:
                t = math.gcd(i,j)
                q = math.gcd(t,l)
                s += q*3
                b.append(q)
            else:
                t = math.gcd(i,j)
                q = math.gcd(t,l)
                s += q*6
                b.append(q)
print(s)
# Original solution
import math
import itertools
def gcd(x,y,z):
    xy = math.gcd(x,y)
    xyz = math.gcd(xy,z)
    return xyz
k1 = int(eval(input()))
k = list(range(1,k1+1))*3
l = []
for i in itertools.combinations(k,3):
    l.append(i)
l = list(set(l))
num = 0
for h in l:
    t = gcd(h[0],h[1],h[2])
    num += t
print(num)    

# Optimized solution
import math
import itertools
def gcd(x,y,z):
    xy = math.gcd(x,y)
    xyz = math.gcd(xy,z)
    return xyz
k1 = int(eval(input()))
k = list(range(1,k1+1))
l = []
for i in itertools.combinations_with_replacement(k,3):
    l.append(i)
num = 0
for h in l:
    t = gcd(h[0],h[1],h[2])
    if h[0] == h[1] == h[2]:
        num += t
    elif h[0] == h[1] or h[1] == h[2] or h[2] == h[0]:
        num += 3*t
    else:
        num += 6*t
print(num)
# Original solution
import math
from functools import reduce
from itertools import combinations

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

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

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

# Optimized solution
import math
from functools import reduce

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

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

n = int(eval(input()))
total = 0
for i in range(1,n+1):
    for j in range(i,n+1):
        for k in range(j,n+1):
            t = 1
            if i != k and i != j and j!= k:
                t = 6
            elif (i == j and i != k) or (i != j and j == k):
                t = 3
            total += gcd(i,j,k)*t
print(total)
# Original solution
import math

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

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

# Optimized solution
from math import gcd

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

for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += gcd(gcd(a,b), c)
print(ans)
# Original solution
import math
K = int(eval(input()))

def computeGCD(x, y):
    while (y):
        x, y = y, x % y

    return x

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

print(sum)

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

def computeGCD(x, y):
    while (y):
        x, y = y, x % y

    return x

sum = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        intermediate = computeGCD(a, b)
        for c in range(1, K+1):
            sum += computeGCD(c, intermediate)

print(sum)