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

# Optimized solution
from math import gcd
ans = 0
k = int(eval(input()))
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            ans += gcd(i,gcd(j,k))
print(ans)
# Original solution
from math import gcd
k = int(eval(input()))
うんち = 0
for デビ in range(1,k+1):
    for デビデ in range(1,k+1):
        for ビル in range(1,k+1):
            うんち += gcd(デビ,gcd(デビデ,ビル))
print(うんち)

# Optimized solution
from math import gcd
k = int(eval(input()))
うんち = 0
for でびさま in range(1,k+1):
    for でびでび in range(1,k+1):
        for でびる in range(1,k+1):
            うんち += gcd(でびさま,gcd(でびでび,でびる))
print(うんち)
# Original solution
import math

k=int(eval(input()))

ans=0

for l in range(1,k+1):
  for m in range(1,k+1):
    for n in range(1,k+1):
      a=math.gcd(l,m)
      if a==1:
        ans+=1
      else:
        ans+=math.gcd(a,n)
        
print(ans)

# Optimized solution
import math

k=int(eval(input()))

ans=0

for l in range(1,k+1):
  for m in range(1,k+1):
    tmp=math.gcd(l,m)
    for n in range(1,k+1):
      gcd=math.gcd(tmp,n)
      ans+=gcd
      
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(1,K+1):
        temp = math.gcd(i,j)
        for k in range(1,K+1):
            ans += math.gcd(temp,k)
print(ans)
# Original solution
import math
from functools import reduce

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

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

print(num)

# Optimized solution
import math
from functools import reduce

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

k = int(eval(input()))
num = 0
for a in range(1,k+1):
    for b in range(a,k+1):
        for c in range(b,k+1):
          x = gcd(a,b,c)
          bai = sum([a==b,b==c,a==c])
          if bai == 0:
            num += x*6
          elif bai == 1:
            num += x*3
          else:
            num += x
            
print(num)
# Original solution
from math import gcd
K = int(eval(input()))
 
c = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for l in range(1,K+1):
            a = gcd(gcd(i,j), l)
            c += a
 
print(c)

# Optimized solution
from math import gcd
K = int(eval(input()))
 
c = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        k = gcd(i,j)
        for l in range(1,K+1):
            a = gcd(k, l)
            c += a
print(c)
# Original solution
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
from math import gcd
from functools import reduce

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

K = ii()
ans = 0

memo = dp3(-1, K+1, K+1, K+1)

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            #l = sorted([i, j, k])
            #l = [i, j, k]
            #a, b, c = l[0], l[1], l[2]
            a, b, c = i, j, k
            if memo[a][b][c] != -1:
                ans += memo[a][b][c]
            else:
                memo[a][b][c] = gcd_list([a, b, c])
                memo[i][k][j] = memo[k][i][j] = memo[k][j][i] = memo[j][i][k] = memo[j][k][i] = memo[i][j][k]
                #memo[i][k][j] = memo[i][j][k]
                #memo[k][i][j] = memo[i][j][k]
                #memo[k][j][i] = memo[i][j][k]
                #memo[j][j][i] = memo[i][j][k]
                #memo[j][i][k] = memo[i][j][k]
                ans += memo[a][b][c]
            #ans += gcd_list([i, j, k])


print(ans)

# Optimized solution
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
from math import gcd
from functools import reduce

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

K = ii()
ans = 0

memo = dp3(-1, K+1, K+1, K+1)

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            #l = sorted([i, j, k])
            #l = [i, j, k]
            #a, b, c = l[0], l[1], l[2]
            #a, b, c = i, j, k
            #if memo[a][b][c] != -1:
                #ans += memo[a][b][c]
            #else:
            #memo[i][j][k] = gcd_list([i, j, k])
                #memo[i][k][j] = memo[k][i][j] = memo[k][j][i] = memo[j][i][k] = memo[j][k][i] = memo[i][j][k]
                #memo[i][k][j] = memo[i][j][k]
                #memo[k][i][j] = memo[i][j][k]
                #memo[k][j][i] = memo[i][j][k]
                #memo[j][j][i] = memo[i][j][k]
                #memo[j][i][k] = memo[i][j][k]
            ans += gcd_list([i, j, k])
            #ans += gcd_list([i, j, k])


print(ans)
# Original solution
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
from math import gcd
from functools import reduce

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

K = ii()
ans = 0

memo = dp3(-1, K+1, K+1, K+1)

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            #l = sorted([i, j, k])
            #l = [i, j, k]
            #a, b, c = l[0], l[1], l[2]
            #a, b, c = i, j, k
            #if memo[a][b][c] != -1:
                #ans += memo[a][b][c]
            #else:
            #memo[i][j][k] = gcd_list([i, j, k])
                #memo[i][k][j] = memo[k][i][j] = memo[k][j][i] = memo[j][i][k] = memo[j][k][i] = memo[i][j][k]
                #memo[i][k][j] = memo[i][j][k]
                #memo[k][i][j] = memo[i][j][k]
                #memo[k][j][i] = memo[i][j][k]
                #memo[j][j][i] = memo[i][j][k]
                #memo[j][i][k] = memo[i][j][k]
            ans += gcd_list([i, j, k])
            #ans += gcd_list([i, j, k])


print(ans)

# Optimized solution
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

#from math import gcd
from functools import reduce

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

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

K = ii()
ans = 0

memo = dp3(-1, K+1, K+1, K+1)

for i in range(1, K+1):
    for j in range(i+1, K+1):
        for k in range(j+1, K+1):
            ans += gcd_list([i, j, k])*6

for i in range(1, K+1):
    for j in range(1, K+1):
        if i!=j:
            ans += gcd_list([i, i, j])*3

for i in range(1, K+1):
    ans += gcd_list([i, i, i])


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

def f(p, n):
  if len(p) == 3:
    global ans
    t = gcd(p[0], p[1])
    t = gcd(t, p[2])
    ans += t
    return t
  for i in range(1, n+1):
    f(p+[i], n)
  
ans = 0
k = int(eval(input()))
f([], k)
print(ans)



# Optimized solution
from math import gcd

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


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


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

print(cnt)


# Optimized solution
import collections
import math
# math.gcd(a,b)
k = int(eval(input()))
cnts = collections.defaultdict(int)
for i in range(1, k+1):
    for j in range(1, k+1):
        cnts[math.gcd(i,j)] += 1
ans = 0
for i in range(1, k+1):
    for key in list(cnts.keys()):
        ans += math.gcd(i, key)*cnts[key]
print(ans)
# Original solution
import math
import itertools
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()))
l = list(itertools.product(list(range(k+1))[1:], repeat=3))
s = 0

for i in l:
    s += gcd(i[0], i[1], i[2])

print(s)

# Optimized solution
import math
import itertools
from functools import reduce

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

k = int(eval(input()))
l = list(itertools.combinations_with_replacement(list(range(k+1))[1:], 3))
s = 0
n = 0

for i in l:
    x = len(set(i))
    if x == 3:
        n = 6
    elif x == 2:
        n = 3
    elif x == 1:
        n = 1

    s += gcd_list(list(i)) * n


print(s)
# Original solution
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

K = int(eval(input()))

GCD = [[0]*200 for i in range(200)]
for i in range(200):
    for j in range(200):
        GCD[i][j] = gcd(i+1, j+1)

tot = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            s = GCD[j-1][k-1]
            t = GCD[i-1][s-1]
            tot += t
print(tot)


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

GCD = [[0]*200 for i in range(200)]
def gcd(x, y):
    if GCD[x-1][y-1] == 0:
        if y == 0:
            return x
        else:
            return gcd(y, x % y)
    else:
        return GCD[x-1][y-1]

tot = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        s = gcd(i, j)
        if s != 1:
            for k in range(1, K+1):
                t = gcd(k, s)
                tot += t
        else:
            tot += K
print(tot)
# 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
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 k in range(1, k+1):
            ans += math.gcd(num, k)
print(ans)
# Original solution
n = int(eval(input()))
from math import gcd

samu = 0

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


print((str(int(samu))))


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

samu = 0

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


print(samu)
# Original solution
k=int(eval(input()))
import math
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(a,l)
print(ans)

# Optimized solution
k=int(eval(input()))
import math
ans=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(i,j)
        	ans+=math.gcd(a,l)
print(ans)
# 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
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(a,gcd(b,c))
      
print(ans)
# 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(a,gcd(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):
    p = gcd(a,b)
    for c in range(1,k+1):
      ans += gcd(p,c)
print(ans)
# Original solution
import math
from functools import reduce
k = int(eval(input()))
def gcd(*numbers):
    return reduce(math.gcd, numbers)
cnt = 0
for a in range(k):
    for b in range(k):
        for c in range(k):
            cnt = cnt + gcd(a+1,b+1,c+1)
print(cnt)


# Optimized solution
import math

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

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
ans = 0
for a in range(K):
    a += 1
    if a == 1:
        ans += K*K
        continue
    for b in range(K):
        b += 1
        if b == 1:
            ans += K
            continue
        tmp = gcd(a, b)
        for c in range(K):
            c += 1
            if c == 1:
                ans += 1
                continue
            dada = gcd(tmp, c)
            ans += dada
            # print(dada)

print(ans)


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

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
ans = 0
for a in range(K):
    a += 1
    if a == 1:
        ans += K*K
        continue
    for b in range(K):
        b += 1
        if b == 1:
            ans += K
            continue
        tmp = gcd(a, b)
        if tmp == 1:
            ans += K
            continue
        for c in range(K):
            c += 1
            if c == 1:
                ans += 1
                continue
            dada = gcd(tmp, c)
            ans += dada
            # print(dada)

print(ans)
# Original solution
import math
a = int(eval(input()))
ans = 0

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

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

for i in range(1, a+1):
    for j in range(1, a+1):
        num = math.gcd(i, j)
        for k in range(1, a+1):
            ans += math.gcd(num, k)
print(ans)
# Original solution
from itertools import product
from math import gcd

K = int(eval(input()))
print((sum([gcd(a,gcd(b,c)) for a,b,c in [i for i in product(list(range(1, K+1)), repeat=3)]]))) 


# 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(a,gcd(b,c))
print(ans)
# 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):
        g = gcd(a,b)
        for c in range(1,K+1):
            ans += gcd(g,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):
        g = gcd(i,j)
        for k in range(1,K+1):
            ans += gcd(g,k)
print(ans)
# Original solution
import math

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

# Optimized solution
import math

n = int(eval(input()))

total1 = 0
for i in range(1, n + 1):
    for j in range(i+1, n + 1):
        for k in range(j+1, n + 1):
            total1 += math.gcd(i, math.gcd(j, k))
total1 = 6*total1

total2 = 0
for i in range(1, n + 1):
    for j in range(i+1, n + 1):
        total2 += math.gcd(i, j)
total2 = 6*total2

total3 = 0
for i in range(1, n + 1):
    total3 += i

print((total1 + total2 + total3))
# Original solution
def u(a,b):
  if(a<b):
    z = b
    b = a
    a = z
  r = a % b
  while(r!=0):
    a = b
    b = r
    r = a % b
  return b
 
l = int(eval(input()))
s = 0
for i in range(1,l+1):
  for i2 in range(1,l+1):
    z = u(i,i2)
    for i3 in range(1,l+1):
      z2 = u(z,i3)
      s+=z2
print (s)

# Optimized solution
def u(a,b):
  if(a<b):
    z = b
    b = a
    a = z
  r = a % b
  while(r!=0):
    a = b
    b = r
    r = a % b
  return b
 
l = int(eval(input()))
s = 0
for i in range(1,l+1):
  for i2 in range(1,l+1):
    z = u(i,i2)
    for i3 in range(1,l+1):
      z2 = u(i3,z)
      s+=z2
print (s)
# Original solution
from functools import lru_cache

@lru_cache(maxsize=100000)
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def resolve():
    k = int(eval(input()))
    l = [None] * k ** 2
    for i in range(k):
        for j in range(k):
            l[i * k + j] = gcd(i + 1, j + 1)
    ans = 0
    for i in l:
        for j in range(k):
            ans += gcd(i, j + 1)
    print(ans)


if __name__ == '__main__':
    resolve()


# Optimized solution
from math import gcd

def resolve():
    k = int(eval(input()))
    l = [None] * k ** 2
    for i in range(k):
        for j in range(k):
            l[i * k + j] = gcd(i + 1, j + 1)
    ans = 0
    for i in l:
        for j in range(k):
            ans += gcd(i, j + 1)
    print(ans)


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


def gcd(a, b, c):
    ans = math.gcd(a, b)
    ans = math.gcd(ans, c)

    # abc = [a, b, c]
    # for _ in [[0, 1], [0, 2], [1, 2]]:
    #     a0 = max(abc[_[0]], abc[_[1]])
    #     a1 = min(abc[_[0]], abc[_[1]])

    #     i = 0
    #     while True:
    #         tmp = a0 % a1
    #         if tmp == 0:
    #             gcds.append(a1)
    #             break
    #         a0 = a1
    #         a1 = tmp

    return ans

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


k = int(eval(input()))

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

print(s)


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


def gcd(a, b, c):
    ans = math.gcd(a, b)
    ans = math.gcd(ans, c)

    return ans

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

k = int(eval(input()))

elem = [i+1 for i in range(k)]

combs = itertools.combinations_with_replacement(elem, 3)

tmp = [1, 2, 3]

s = 0
for comb in combs:
    s += sum(tmp[:len(set(comb))]) * gcd(comb[0], comb[1], comb[2])
# for a in range(1, k+1):
#     for b in range(1, k+1):
#         for c in range(1, k+1):
#             s += gcd(a, b, c)

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

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

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

# Optimized solution
import math
k = int(eval(input()))
cnt = 0
for a in range(1, k+1):
    for b in range(a+1, k+1):
        for c in range(b+1, k+1):
            cnt += math.gcd(math.gcd(a, b), c) * 6

for a in range(1, k+1):
    for b in range(a+1, k+1):
        cnt += math.gcd(a, b) * 6

for i in range(1, k+1):
    cnt += i
print(cnt)
# Original solution
import itertools
import math
from functools import reduce

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

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

# Optimized solution
import itertools
import math
from functools import reduce

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

k = int(eval(input()))
l = list(range(1, k+1))                                                
s = 0

for i in itertools.product(l, repeat=3):
  s += gcd(*i)
print(s)
# Original solution
from functools import reduce
import math

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

k = int(eval(input()))

sum = 0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      sum += gcd(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):
    ab = math.gcd(a,b)
    for c in range(1,k+1):
      sum += math.gcd(ab, c)

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

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

print(ans)


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

import math
K = int(eval(input()))
ans_list = []
ans = 0
for i in range(1, K + 1):
    for j in range(1,K+1):
        ans_list.append(math.gcd(i,j))
for i in range(1,K+1):
    for j in range(0,len(ans_list)):
        ans += math.gcd(i,ans_list[j])

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


def gcd_list(numbers):
    return reduce(math.gcd, numbers)
K = int(eval(input()))
count = 0 
a = [0,0,0]
for i in range(1,K+1):
  a[0] = i
  for j in range(1,K+1):
    a[1] = j
    for k in range(1,K+1):
      a[2] = k
      count += gcd_list(a)


print(count)

# Optimized solution
from math import gcd
k=int(eval(input()))
cnt=0
for i in range(1,k+1):
  for p in range(1,k+1):
    for q in range(1,k+1):
      gcd1=gcd(i,p)
      
      cnt+=gcd(gcd1,q)
 
      
print(cnt)
# 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
from math import gcd

K = int(eval(input()))

result = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        t = gcd(a, b)
        for c in range(1, K + 1):
            result += gcd(t, c)
print(result)
# Original solution
import math

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

for l in range(1,k+1):
    for m in range(1,k+1):
        for n in range(1,k+1):
            tmp = math.gcd(l,m)
            if tmp == 1:
                cnt += 1
            else:
                cnt += math.gcd(tmp,n)
            
print(cnt)


# Optimized solution
#C

import math

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

for i in range(1,k+1):
    for j in range(i,k+1):
        tmp = math.gcd(i,j)
        for l in range(1,k+1):
            if i != j:
                cnt += 2 * math.gcd(tmp,l)
            else:
                cnt += math.gcd(tmp,l)
            
print(cnt)