CodeEff/ECCO huggingface dataset:
# Original solution
import math
from functools import reduce
 
def gcd_list(a,b,c):
    return reduce(math.gcd, [a,b,c])
 
n = int(eval(input()))
cnt = 0
for i in range(1,n + 1):
    for j in range(1,n + 1):
        for k in range(1,n + 1):
            
            cnt += gcd_list(i,j,k)
print(cnt)

# Optimized solution
import math

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

ans = 0

import math

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

print(ans)

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

ans = 0

import math

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

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

def mygcd(x,y):
    a = min(x,y)  # 最小値
    b = max(x,y)  # 最大値
    r = 2  # 余り
    while r != 0:
        r = b % a
        b = a
        a = r
    return b

ans = 0
for i in range(k):
    for j in range(k):
        for l in range(k):
            ans += mygcd(mygcd(i+1,j+1),l+1)

print(ans)

# Optimized solution
K   = int(eval(input()))
Sum = 0
def mygcd(x,y):
    a = min(x,y)  # 最小値
    b = max(x,y)  # 最大値
    r = 2  # 余り
    while r != 0:
        r = b % a
        b = a
        a = r
    return b

for A in range(1,K+1):
    for B in range(1,K+1):
        AB = mygcd(A,B)
        if AB==1:
            Sum = Sum+K
        else:
            for C in range(1,K+1):
                Sum = Sum+mygcd(AB,C)
print(Sum)
# Original solution
import math

K=int(eval(input()))
ans=0
for i in range(1,K+1,1):
    for j in range(1,K+1,1):
        for k in range(1,K+1,1):
            a = math.gcd(i,j)
            b = math.gcd(a,k)
            ans += b
print(ans)            

# Optimized solution
import math

N=int(eval(input()))
ans=0
for i in range(1,N+1,1):
    for j in range(i,N+1,1):
        for k in range(j,N+1,1):
            list =[i,j,k]
            ff=len(set(list))
            a = math.gcd(i,j)
            b = math.gcd(a,k)
            if ff == 1:
                ans += b
            elif ff == 2:
                ans += 3*b
            else:
                ans += 6*b
print(ans)
# Original solution
import math

K=int(eval(input()))
ans=0
for i in range(1,K+1,1):
    for j in range(1,K+1,1):
        a = math.gcd(i,j)
        for k in range(1,K+1,1):
            b = math.gcd(a,k)
            ans += b

print(ans) 

# Optimized solution
import math

K=int(eval(input()))
ans=0
for i in range(1,K+1,1):
    for j in range(1,K+1,1):
        for k in range(1,K+1,1):
            a = math.gcd(i,j)
            b = math.gcd(a,k)
            ans += b

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

def gcd (*numbers):
    return reduce(math.gcd,numbers)
k = int(eval(input()))
total = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        for x in range(1,k+1):
            total += gcd(i,j,x)
print(total)

# 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

        else:
            for c in range(1,k+1):
                ans += math.gcd(ab,c)
print(ans)
# Original solution
import math

def main():
    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):
                tmp = math.gcd(i,j)
                ans += math.gcd(tmp,k)

    print(ans)

if __name__ == "__main__":
    main()

# Optimized solution
import math

def main():
    n = int(eval(input()))
    ans = 0
    a = {}
    for i in range(1,n+1):
        for j in range(1,n+1):
            tmp = math.gcd(i,j)
            a[tmp] = a.get(tmp, 0)
            a[tmp] += 1


    for key, val in list(a.items()):
        for j in range(1, n+1):
            ans += math.gcd(key,j) * val

    print(ans)

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

def gcd (*numbers):
    return reduce(math.gcd, numbers)
    def  gcd_list (numbers):
        return reduce(math.gcd, numbers)
ans = 0

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

print(ans)


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

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

print(ans)
# Original solution
#C - Sum of gcd of Tuples (Easy)
K = int(eval(input()))
DP =[]
ans = 0
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, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            a = gcd_list([i, j, k])
            DP.append(a)

for l in range(len(DP)):
    ans += DP[l]
print(ans)

# Optimized solution
#C - Sum of gcd of Tuples (Easy)
K = int(eval(input()))
DP =[]
ans = 0
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, K + 1):
    for j in range(1, K + 1):
        a = math.gcd(i,j)
        for k in range(1,K+1):
            b = math.gcd(a,k)
            ans += b

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

print(ans)
# Original solution
import itertools
import functools

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
def gcd(nums):
    return functools.reduce(euclid, nums)

k = int(eval(input()))
ans = 0
for v in itertools.combinations_with_replacement([i+1 for i in range(k)], 3):
    if len(set(v)) == 1:
        ans = ans + gcd(v) * 1
    elif len(set(v)) == 2:
        ans = ans + gcd(v) * 3
    elif len(set(v)) == 3 :
        ans = ans + gcd(v) * 6
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):
        ans_=gcd(i,j)
        for l in range(1,k+1):
            ans+=gcd(ans_,l)
print(ans)
# Original solution
import math
import itertools
ans = 0
k = int(eval(input()))

permutations_lis = list(itertools.product(list(range(1,k+1)), repeat=3))
for one_case in permutations_lis:
    ans += math.gcd(one_case[0],math.gcd(one_case[1],one_case[2]))
print(ans)

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

# Optimized solution
import math
ans = 0
n = int(eval(input()))
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):
            ans += math.gcd(t,k)
print(ans)
# Original solution
def gcd(x1,x2):
    r=0
    while True:
        if x1==x2:
            r=x1
            break
        elif x1<x2:
            x2=x2-x1
        else:
            x1=x1-x2
    return r

x = int(eval(input()))

ans=0

for a in range(1,x+1):
    for b in range(1,a+1):
        for c in range(1,b+1):
            gcd1=gcd(a,b)
            gcd2=gcd(gcd1,c)
            if a==b and b==c:
                ans += gcd2
            elif a==b or b==c or c==a:
                ans += 3*gcd2
            else:
                ans += 6*gcd2

print(ans)

# Optimized solution
import sys
sys.setrecursionlimit(10**8)

def gcd(p,q): #p<q
    if q%p==0:
        return p
    return gcd(q%p,p)

x = int(eval(input()))

ans=0

for a in range(1,x+1):
    for b in range(1,a+1):
        for c in range(1,b+1):
            gcd1=gcd(a,b)
            gcd2=gcd(gcd1,c)
            if a==b and b==c:
                ans += gcd2
            elif a==b or b==c or c==a:
                ans += 3*gcd2
            else:
                ans += 6*gcd2

print(ans)
# Original solution
K = int(eval(input()))
def pgcd(x,y):
  while y>0:
    x,y=y,x%y
  return x
s = 0
for a in range(1,K+1):
  for b in range(1,K+1):
    for c in range(1,K+1):
      s+=pgcd(pgcd(a,b),c)
print(s)

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

# Optimized solution
import math
K = int(eval(input()))
a = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    m = math.gcd(i,j)
    for h in range(1,K+1):
      l = math.gcd(h,m)
      a += l
print(a)
# Original solution
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: list(map(int, INPUT().split()))
S_MAP = lambda: list(map(str, INPUT().split()))
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    K = INT()

    gcdf = lambda *numbers: reduce(gcd, numbers)
    ans = 0
    for i in range(K):
        for j in range(K):
            for k in range(K):
                ans += gcdf(i + 1, j + 1, k + 1)

    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: list(map(int, INPUT().split()))
S_MAP = lambda: list(map(str, INPUT().split()))
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    K = INT()

    gcdf = lambda *numbers: reduce(gcd, numbers)
    ans = 0
    for t in list(combinations_with_replacement(list(range(K)), 3)):
        k = 3
        if t[0] == t[1] and t[1] == t[2] and t[2] == t[0]:
            k = 1
        elif t[0] != t[1] and t[1] != t[2] and t[2] != t[0]:
            k = 6

        ans += k * gcdf(t[0] + 1, t[1] + 1, t[2] + 1)

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
import math
from functools import reduce
K = int(eval(input()))
CNT= 0
def gcd(*numbers):
    return reduce(math.gcd, numbers)
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            CNT += gcd(i,j,k)
print(CNT)

# Optimized solution
import math
from functools import reduce
K = int(eval(input()))
CNT= 0
def gcd(*numbers):
    return reduce(math.gcd, numbers)
for i in range(1,K+1):
    for j in range(1,K+1):
        GCD = gcd(i,j)
        if GCD == 1:
            CNT += K
        else:
            for k in range(1, K+1):
                if gcd(GCD,k) != 1:
                    CNT += gcd(GCD,k)
                else:
                    CNT += 1
print(CNT)
# Original solution
import math
import sys
input = sys.stdin.readline
from functools import reduce
K = int(eval(input()))
CNT= 0
def gcd(*numbers):
    return reduce(math.gcd, numbers)
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            CNT += gcd(i,j,k)
print(CNT)

# Optimized solution
import sys
input = sys.stdin.readline
def main():
   K = int(eval(input()))
   CNT = 0
   for i in range(1, K+1):
       for j in range(1, K+1):
           A = gcd(i, j)
           for k in range(1, K+1):
               CNT += gcd(A, k)
   print(CNT)

def gcd(p, q):
    if p%q == 0:
        return q
    return gcd(q, p%q)

if __name__ == '__main__':
    main()
# Original solution
# -*- coding: utf-8 -*-
import math
# 整数の入力
n = int(eval(input()))
s = 0
for i in range(1, n + 1):
    for j in range(1, n + 1):
        for k in range(1, n + 1):
            gcd = math.gcd(math.gcd(i, j),k)
            s += gcd
print(s)

# Optimized solution
# -*- coding: utf-8 -*-
import math
# 整数の入力
n = int(eval(input()))
s = 0
for i in range(1, n + 1):
    for j in range(i, n + 1):
        for k in range(j, n + 1):
            gcd = math.gcd(math.gcd(i, j),k)
            if i == j and j == k:
                s += gcd
            elif i == j or j == k or k ==i:
                s += gcd * 3
            else:
                s += gcd * 6
# for i in range(1, n + 1):
#     for j in range(1, n + 1):
#         for k in range(1, n + 1):
#             gcd = math.gcd(math.gcd(i, j),k)
#             s += gcd
print(s)
# Original solution
import math
K = int(eval(input()))
S = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for l in range(1,K+1):
      S = S + math.gcd(l, math.gcd(j,i))

print(S)


# Optimized solution
import math
K = int(eval(input()))
A = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for l in range(1,K+1):
            A += math.gcd(math.gcd(l,j),i)
print(A)
# Original solution
def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)
N=int(eval(input()))
s=0
for i in range(1,N+1):
  for j in range(1,N+1):
    for h in range(1,N+1):
      a=gcd(i,j)
      s+=gcd(a,h)
print(s)

# Optimized solution
def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)
N=int(eval(input()))
s=0
for i in range(1,N+1):
  for j in range(i+1,N+1):
    for h in range(j+1,N+1):
      a=gcd(i,j)
      s+=6*gcd(a,h)
for p in range(1,N+1):
  for q in range(1,N+1):
    if p==q:
      s+=p
    else:
      s+=3*gcd(p,q)
print(s)
# Original solution
import math
from functools import reduce

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

k = int(eval(input()))

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

print(ans)
            

# Optimized solution
import math

def gcd(*numbers):
    return math.gcd( math.gcd(a, b), c)

k = int(eval(input()))

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

print(ans)
# Original solution
#coding:utf-8
import math
import itertools
from functools import reduce

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

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

    num = [i for i in range(1,k+1)]
    comb = tuple(itertools.product(num, repeat=3))


    for i in comb:
        ans += gcd(i)

    print(ans)

if __name__ == "__main__":
    main()



# Optimized solution
#coding:utf-8
from math import gcd

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

    print(ans)

if __name__ == "__main__":
    main()
# Original solution
# -*- coding: utf-8 -*-
K = int(eval(input()))

def gcd(p, q):
  if(p % q == 0):
    return q
  else:
    return gcd(q, p % q)

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

sum2 = 0
for a in range(1, K+1):
  for c in range(a+1, K+1):
      sum2 += gcd(a, c)

sum3 = 0
for a in range(1, K+1):
  sum3 += a

sum = sum1*6 + sum2*6 + sum3
print(sum)


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

def gcd(p, q):
  if(p % q == 0):
    return q
  else:
    return gcd(q, p % q)

sum1 = 0
for c in range(1, K+1):
  for b in range(c+1, K+1):
    d = gcd(b, c)
    for a in range(b+1, K+1):
      sum1 += gcd(a, d)

sum2 = 0
for a in range(1, K+1):
  for c in range(a+1, K+1):
      sum2 += gcd(a, c)

sum3 = 0
for a in range(1, K+1):
  sum3 += a

sum = sum1*6 + sum2*6 + sum3
print(sum)
# Original solution
import math
from functools import reduce


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


def main():
    K = int(eval(input()))
    s = sum([gcd(i+1, j+1, k+1) for i in range(K) for j in range(K) for k in range(K)])

    print(s)


if __name__=="__main__":
    main()


# Optimized solution
import math


def main():
    K = int(eval(input()))
    s = 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):
                s += math.gcd(tmp, k)

    print(s)


if __name__=="__main__":
    main()
# Original solution
import math
ans = 0
def gcd_list(a):
    tmp = math.gcd(a[0],a[1])
    return math.gcd(tmp,a[2])
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):
            a = [i,j,k]
            ans += gcd_list(a)
print(ans)

# Optimized solution
import math
ans = 0
k = int(eval(input()))
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):
            ans += math.gcd(tmp,k)
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 = 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(1,K+1,1):
    for j in range(i,K+1,1):
        for k in range(j,K+1,1):
            if i == j and j==k:
                ans = ans + math.gcd(math.gcd(i,j),k)
            elif i == j and j != k:
                ans = ans + 3*math.gcd(math.gcd(i,j),k)
            elif i != j and j == k:
                ans = ans + 3*math.gcd(math.gcd(i,j),k)
            elif i != j and j != k:
                ans = ans + 6*math.gcd(math.gcd(i,j),k)
print(ans)
# Original solution
import math
num = (int)(eval(input()))
total = 0
 
for i in range(1, num + 1):
  for j in range(1, num + 1):
    sub = math.gcd(i, j)
    for k in range(1, num + 1):
      total += math.gcd(sub, k)
print(total)

# Optimized solution
from math import gcd
num = (int)(eval(input()))
total = 0
 
for i in range(1, num + 1):
  for j in range(1, num + 1):
    sub = gcd(i, j)
    for k in range(1, num + 1):
      total += gcd(sub, k)
print(total)
# 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(1,k+1):
        tmp = gcd(i,j)
        for m in range (1,k+1):
            ans += gcd(tmp,m)

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

print(ans)
# Original solution
n = int(eval(input()))
ans = 0

def gcd(a,b):
    if a>b:
        p = a
        q = b
    else:
        p = b
        q = a
    d = q
    while p % q != 0:
        d = p % q
        p = q
        q = d
    return d


for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            if i==1 or j==1 or k==1:
                ans += 1
            elif abs(i-j)==1 or abs(j-k)==1 or abs(k-i)==1:
                ans += 1
            else:
                ans += gcd(gcd(i,j),k)

print(ans)


# Optimized solution
n = int(eval(input()))
ans = 0
 
def max(a,b):
    if a>b:
        return a
    else:
        return b
 
def min(a,b):
    if a<b:
        return a
    else:
        return b
 
def gcd(a,b):
    p = max(a,b)
    q = min(a,b)
    d = q
    while p % q != 0:
        d = p % q
        p = q
        q = d
    return d
 
 
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)