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


k = int(eval(input()))

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

k += 1
ans = 0


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


print(ans)


# Optimized solution
import math
from functools import reduce


k = int(eval(input()))

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

k += 1
ans = 0

for i in range(1,k):
    for j in range(i,k):
        #print(i,j)
        if i == j:
            ans += gcd(i,j)
        else:
            ans += gcd(i,j)*6

for i in range(1,k):
    for j in range((i+1),k):
        for h in range((j+1),k):
            #print(i,j,h)
            ans += gcd(i,j,h)*6


print(ans)
# Original solution
import math, itertools
from functools import reduce
def gcd_list(numbers):
    return(reduce(math.gcd,numbers))
k=int(eval(input()))
ans=0
for numbers in itertools.product(list(range(1,k+1)),repeat=3):
    ans+=gcd_list(numbers)
print(ans)

# Optimized solution
import math, itertools
from functools import reduce
def gcd_list(numbers):
    return(reduce(math.gcd,numbers))
k=int(eval(input()))
ans=0
for numbers in itertools.combinations_with_replacement(list(range(1,k+1)),3):
    a,b,c=numbers
    if a==b==c:
        ans+=gcd_list(numbers)
    elif a!=b and a!=c and b!=c:
        ans+=6*gcd_list(numbers)
    else:
        ans+=3*gcd_list(numbers)
print(ans)
# Original solution
k = int(eval(input()))
def gcd1 (a, b):
    while True:
        if (a < b):
            a, b = b, a
        c = a%b
        if (c == 0):
            return (b)
        else:
            a = b
            b = c

def gcd2 (a, b, c):
    tmp = gcd1(a, b)
    ans = gcd1(tmp, c)
    return (ans)

count = 0
for i in range(k):
    for j in range(k):
        for l in range(k):
            tmp = gcd2(i + 1, j + 1, l + 1)
            count = count + tmp
print(count)


# Optimized solution
k = int(eval(input()))
def gcd1 (a, b):
    while True:
        if (a < b):
            a, b = b, a
        c = a%b
        if (c == 0):
            return (b)
        else:
            a = b
            b = c

def gcd2 (a, b, c):
    tmp = gcd1(a, b)
    ans = gcd1(tmp, c)
    return (ans)

count = 0
for i in range(k):
    for j in range(i, k):
        for l in range(j, k):
            tmp = gcd2(i + 1, j + 1, l + 1)
            if (i == j == l):
                count = count + tmp
            elif (i == j or j == l):
                count = count + tmp*3
            else:
                count = count + tmp*6
print(count)
# 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 n in range(1,K+1):
			tmp = math.gcd(i,j)
			ans += math.gcd(tmp,n)
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 n in range(1,K+1):
			ans += math.gcd(tmp,n)
print(ans)
# Original solution
import math
import fractions

k = eval(input())

sum = 0
for a in range(int(k)):
    for b in range(int(k)):
        x = math.gcd(a+1, b+1)
        for c in range(int(k)):
            y = math.gcd(x, c+1)
            sum += y
print(sum)


# Optimized solution
import math
k = int(eval(input()))
total = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        g1 = math.gcd(a, b)
        for c in range(1, k+1):
            g2 = math.gcd(g1, c)
            total += g2
print(total)
# Original solution
# 3重ループでテスト

from functools import reduce

k = int(eval(input()))

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

def gcds(*nums):
	return reduce(gcd, nums)

res = 0
for a in range(1, k + 1):
	for b in range(1, k + 1):
		for c in range(1, k + 1):
			res += gcds(a, b, c)

print(res)

# Optimized solution
from math import gcd

k = int(eval(input()))

gcd_sum = [0] * 201
res = 0

for i in range(1, k + 1):
	for j in range(1, k + 1):
		gcd_sum[i] += gcd(i, j)

for a in range(1, k + 1):
	for b in range(1, k + 1):
		g = gcd(a, b)
		res += gcd_sum[g]

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

sum = 0

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


for a in range(1, k + 1):
    for b in range(1, k + 1):
        ab_gcd = gcd(a, b)
        for c in range(1, k + 1):
            abc_gcd = gcd(c, ab_gcd)
            sum += abc_gcd
        
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_gcd = math.gcd(a, b)
        for c in range(1, K + 1):
            ans += math.gcd(ab_gcd, 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 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()))
s = 0
i = 0
d = [0]*k*k
for a in range(1,k+1):
    for b in range(1,k+1):
        d[i] = math.gcd(a,b)
        i+=1
for c in range(1,k+1):
        s += sum([math.gcd(x,c) for x in d])
print(s)
# Original solution
k=int(eval(input()))
from math import gcd
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for m in range(1,k+1):
      temp=gcd(i,j)
      ans=ans+gcd(temp,m)
print(ans)


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

N = int(eval(input()))
s = 0

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

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

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


print(s)



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

N = int(input())
s = 0

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

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

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


print(s)
'''

import math
from functools import reduce
import itertools


N = int(eval(input()))
s = 0

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

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

seq = list(range(1, N+1))
comb = list(itertools.combinations_with_replacement(seq,3))

#print(seq)
#print(comb)

i = 1
for c in comb:
    if i == 1 or (c[0] == c[1] and c[1] == c[2]):
        s += gcd(c[0], c[1], c[2])
    elif c[0] != c[1] and c[1] != c[2] and c[0] != c[2]:
        s = s + gcd(c[0], c[1], c[2]) * 6
    else:
        s = s + gcd(c[0], c[1], c[2]) * 3
    i += 1

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


# Optimized solution
import math

N=int(eval(input()))
ans=0
for i in range(1,N+1):
    for j in range(i,N+1):
        for k in range(j,N+1):
            if i==j and j==k:
                ans+=i
            elif i<j and j<k:
                ans+=6*math.gcd(i,math.gcd(j,k))
            else:
                ans+=3*math.gcd(i,math.gcd(j,k))
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 a in range(k+1):
    for b in range(k+1):
        for c in range(k+1):
            if a != 0 and b != 0 and c != 0:
                sum = sum + gcd(a,b,c)

print(sum)

# Optimized solution
import math
from functools import reduce

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

for a in range(k+1):
    for b in range(k+1):
        tmp = math.gcd(a,b)
        for c in range(k+1):
            if a != 0 and b != 0 and c != 0:
                sum = sum + math.gcd(tmp,c)

print(sum)
# Original solution
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def fb(i):
    if i % 15 == 0 or i % 3 == 0 or i % 5 == 0:
        return True
    else:
        return False


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    ret = 0
    for n in range(1, N+1):
        for m in range(1, N + 1):
            for l in range(1, N + 1):
                ret += math.gcd(math.gcd(n,m),l)
    print(ret)


if __name__ == '__main__':
    main()


# Optimized solution
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    ret = 0
    for a in range(1, N + 1):
        for b in range(1, N + 1):
            q = math.gcd(a, b)
            for c in range(1, N + 1):
                ret += math.gcd(q, c)
    print(ret)


if __name__ == '__main__':
    main()
# Original solution
import math
def gcd_arg3(a,b,c):
    return math.gcd(a,math.gcd(b,c))

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

print(sum)

# Optimized solution
import math
def gcd_arg3(a,b,c):
    return math.gcd(a,math.gcd(b,c))

k = int(eval(input()))

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

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

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

# Optimized solution
from math import gcd
ans=0
i = int(eval(input()))
for a in range(1,i+1):
  for b in range(1,i+1):
    for c in range(1,i+1):
      n=gcd(gcd(a,b),c)
      ans+=n
print(ans)
# Original solution
from math import gcd
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    K = int(readline())

    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)


if __name__ == "__main__":
    main()


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

K = int(readline())

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 math
from functools import reduce


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


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

# Optimized solution
import math
from functools import reduce
import itertools


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


K = int(eval(input()))
l = list(range(1, K + 1))
ans = K * (K + 1) // 2
for i in itertools.combinations(l, 2):
    ans += 3*(gcd(i[0], i[0], i[1])+gcd(i[0], i[1], i[1]))
for i in itertools.combinations(l, 3):
    ans += 6*gcd(i[0], i[1], i[2])

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

# Optimized solution
import math
ans = 0
c = 0
K = int(eval(input()))
for i in range(1,K+1):
    for j in range(1,K+1):
        c = math.gcd(i,j)
        for m in range(1,K+1):
            ans += math.gcd(c,m) 
print(ans)
# Original solution
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(eval(input()))


def S(): return eval(input())


def MI(): return list(map(int, input().split()))


def MS(): return list(map(str, input().split()))


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in eval(input())]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True

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


def gcd_n(a, n):
    ans = a[0]
    for i in range(1, n):
        ans = gcd(ans, a[i])
    return ans


def divisor(n):
    ret = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ret.append(i)
            if n // i != i:
                ret.append(n // i)
    return ret


def main():
    K = I()
    ans = 0

    for a in range(1, K+1):
        for b in range(1, K+1):
            for c in range(1, K+1):
                # print(a, b, c, gcd_n([a, b, c], 3))
                ans += gcd_n([a, b, c], 3)

    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True

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


def main():
    K = I()
    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


import math
rst = 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):
            rst += math.gcd(k, tmp)
print(rst)


# Optimized solution


from math import gcd as g


k = int(eval(input()))
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        temp = g(a, b)
        for c in range(1, k+1):
            ans += g(temp, c)


print(ans)
# Original solution
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

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

k = inp()
res = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        xx = gcd(i,j)
        for l in range(1,k+1):
            res += gcd(xx,l)
print(res)

# Optimized solution
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

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

k = inp()
res = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        xx = gcd(i,j)
        for l in range(1,k+1):
            res += gcd(xx,l)
print(res)
# Original solution
import functools


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


def gcd(nums):
    return functools.reduce(euclid, nums)


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

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


K = int(eval(input()))

sum_gcd = 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):
            sum_gcd += gcd(g, k)
print(sum_gcd)
# Original solution
import math
from functools import reduce
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):
            nums = [a, b, c]
            gcd = reduce(math.gcd, nums)
            sum += gcd
print(sum)

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

sum = 0

def gcd(x, y): # ユークリッドの互除法
    if y > x:
        y,x = x,y
    while y > 0:
        r = x%y
        x = y
        y = r
    return x

import math

for i in range(1,k+1):
    for m in range(1,k+1):
        sub = gcd(i,m)
        for l in range(1,k+1):
            sum += gcd(sub,l)
print(sum)


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

sum = 0

def gcd(x, y): # ユークリッドの互除法
    if y > x:
        y,x = x,y
    while y > 0:
        r = x%y
        x = y
        y = r
    return x

for i in range(1,k+1):
    for m in range(1,k+1):
        for l in range(1,k+1):
            sum += gcd(gcd(i,m),l)
print(sum)
# Original solution
import math

K = int(eval(input()))

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

print(ans)


# Optimized solution
import math

K = int(eval(input()))

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

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

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

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

result = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            result += gcdl(a,b,c)

print(result)


# Optimized solution
K = list(range(1,int(eval(input()))+1))

import itertools

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

result = 0


if len(K)>=3:
    for i in list(itertools.combinations(K,3)):
        result += gcd(gcd(i[0],i[1]),i[2])*6

if len(K)>=2:
    for i in list(itertools.combinations(K,2)):
        result += gcd(i[0],i[1])*6

for i in list(itertools.combinations(K,1)):
    result += i[0]

print(result)
# Original solution
from collections import defaultdict
import math
k= int(eval(input()))
ans = 0
dic = defaultdict(int)
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            if (a,b) not in dic:
                x = math.gcd(a,b)
                dic[(a,b)] = x
            x = dic[(a,b)]
            if (x,c) not in dic:
                x = math.gcd(x,c)
                dic[(x,c)] = x
            ans += dic[(x,c)]
print(ans)


# Optimized solution
import math
k= int(eval(input()))
ans = 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):
            ans += math.gcd(x,c)
print(ans)
# Original solution
#162C
#Sum of gcd of Tuples (Easy)

import math
from functools import reduce

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

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

# Optimized solution
#162C
#Sum of gcd of Tuples (Easy)

import math

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

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

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

# Optimized solution
import math

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

# Optimized solution
import math

K = int(eval(input()))
SUM = 0
gcdlist = []
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            gcd1 = math.gcd(i,j)
            gcd2 = math.gcd(gcd1,k)
            if i == j and j== k:
                SUM += gcd2
            elif i == j or j == k or k == i:
                SUM += gcd2*3
            else:
                SUM += gcd2*6

print(SUM)
# Original solution
import math

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

print(sum)

# Optimized solution
import math

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

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

# Optimized solution
import math
n = int(eval(input()))
lis = [[0] * n for i in range(n)]
for i in range(n):
  for j in range(n):
    lis[i][j] = math.gcd(i+1,j+1)
ans = 0
for i in range(n):
  for j in range(n):
    for k in range(n):
      ans += lis[i][lis[k][j]-1]
print(ans)