CodeEff/ECCO huggingface dataset:
# Original solution
k = int(eval(input()))
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
ans = 0
dic = {}
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            tmp = [a,b,c]
            tmp = list(sorted(tmp))
            moji = list(map(str,tmp))
            moji = " ".join(moji)
            try:
                dic[moji]
                ans += dic[moji]
            except:
                num = gcd(tmp[0],tmp[1],tmp[2])
                ans += num
                dic[moji] = num

print(ans)

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

# Optimized solution
import math
k=int(eval(input()))
res=0
A=[]
for a in range(1,k+1):
    for b in range(1,k+1):
        A.append(math.gcd(a,b))
for a in A:
    for c in range(1,k+1):
        res+=math.gcd(a,c)
print(res)
# Original solution
import math
from functools import reduce
import itertools


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

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

line = int(eval(input()))

a = list(range(1,line + 1))
b = list(range(1,line + 1))
c = list(range(1,line + 1))

result = list(itertools.product(a,b,c))
#print(result)

all = 0

for i in result:
    tmp = gcd(i[0], i[1], i[2])
    all += tmp

print(all)

# Optimized solution
from math import gcd

line = int(eval(input()))

ans = 0

for a in range(1, line + 1):
    for b in range(1, line + 1):
        c = gcd(a,b)
        for d in range(1, line + 1):
            ans += gcd(d,c)
print(ans)
# Original solution
import math
from functools import reduce

k = int(eval(input()))
kl = [i for i in range(1, k+1)]


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


total = 0
for i in kl:
    for j in kl:
        for k in kl:
            total += gcd(i, j, k)


print(total)


# Optimized solution
import math

k = int(eval(input()))
kl = [i for i in range(1, k+1)]


total = 0
dp = {}
for i in kl:
    for j in kl:
        tmp = math.gcd(i, j)
        for k in kl:
            total += math.gcd(tmp, k)


print(total)
# Original solution
import math
K = int(eval(input()))
ans = 0
result = 0
dp = [[[0 for i in range(K+1)] for i in range(K+1)]for i in range(K+1)]
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            if dp[i][j][k] == 0:
                x = math.gcd(i,j)
                y = math.gcd(j,k)
                ans = math.gcd(x,y)
                dp[i][j][k] = ans
                dp[j][i][k] = ans
                dp[k][i][j] = ans
                dp[k][j][i] = ans
                result += ans
            else:
                result += max(dp[i][j][k],dp[j][i][k],dp[k][i][j],dp[k][j][i])
print(result)

# Optimized 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):
            x = math.gcd(i,j)
            y = math.gcd(j,k)
            ans += math.gcd(x,y)
print(ans)
# Original solution
K = int(eval(input()))
import math  
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 + math.gcd(math.gcd(a,b),c)
print(ans)        

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

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

# Optimized solution
import sys
from math import gcd
input = sys.stdin.readline
def main():
    K = int(eval(input()))
    total = 0
    for a in range(1,K+1):
        for b in range(1,K+1):
            tmp = gcd(a,b)
            for c in range(1,K+1):
                total+=gcd(tmp,c)
    print(total)
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()))

sum = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      #print ("gcd({} {} {} )".format(i,j,k))
      sum += gcd(i,j,k)
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 k in range(1,K+1):
      sum+=math.gcd(temp,k)
print (sum)
# Original solution
import math
K = int(eval(input()))
count = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            tmp = 0
            tmp = math.gcd(i, j)
            count += math.gcd(tmp, k)
print(count)

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

print( sum )

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

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

print(ans)
# Original solution
def main():
    K = int(eval(input()))
    from math import gcd
    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)


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    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)


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

K = int(eval(input()))

res = 0

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

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

print(res)

# Optimized solution
import math
from collections import defaultdict

d = defaultdict(lambda : defaultdict(int))

K = int(eval(input()))

res = 0

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

for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            res += d[d[a][b]][c]

print(res)
# Original solution
import math

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

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


# Optimized solution
import math

k = int(eval(input()))
sum = 0
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)
# Original solution
import math

N = int(eval(input()))

ans = 0

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

print(ans)

# Optimized solution
import math
import itertools

N = int(eval(input()))

ans1 = sum(range(1, N+1))

ans2 = 0
for x in itertools.combinations(list(range(1, N+1)), 3):
  ans2 = ans2 + math.gcd(math.gcd(x[0],x[1]),x[2]);


ans2 = ans2 * 6

ans3 = 0
for x in itertools.combinations(list(range(1, N+1)), 2):
  ans3 = ans3 + math.gcd(math.gcd(x[0],x[0]),x[1]);


ans3 = ans3 * 6

print((ans1 + ans2 + ans3))
# Original solution
import sys
import itertools
from functools import reduce
from math import gcd

n = int(sys.stdin.read())
print((sum(reduce(gcd, abc) for abc in itertools.product(list(range(1, n + 1)), repeat=3))))

# Optimized solution
import sys
import itertools
from math import gcd

n = int(sys.stdin.read())
print((sum(gcd(gcd(abc[0], abc[1]), abc[2]) for abc in itertools.product(list(range(1, n + 1)), repeat=3))))
# Original solution
import math
K = int(eval(input()))

count = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for q in range(1, K+1):
            count += math.gcd(math.gcd(i,j),q)
print(count)

# Optimized solution
import math

K = int(eval(input()))

count = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            count += math.gcd(math.gcd(i,j), k)
print(count)
# 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
def gcd(p, q):
  while q != 0:
    r = p % q
    p = q
    q = r
  return p

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


# Optimized solution
from sys import setrecursionlimit
setrecursionlimit(1000000)

def Euclid_algorithm(a:int, b:int)->int:
    if a < b:
        a, b = b, a
    else:
        pass
    if b == 0:
        return a
    else:
        return Euclid_algorithm(b, a % b)

k = int(eval(input()))
ans = 0
for h in range(1, k+1):
    for i in range(1, k+1):
        for j in range(1, k+1):
            ans += Euclid_algorithm(h, Euclid_algorithm(i, j))
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):
      g = math.gcd(i,j)
      ans += math.gcd(g,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):
    g = math.gcd(i,j)
    for k in range(1,k+1):
      ans += math.gcd(g,k)
print(ans)
# Original solution
import math
from functools import reduce

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

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

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

res = sum([math.gcd(math.gcd(a+1, b+1), c+1) for a in range(K) for b in range(K) for c in range(K)])
print(res)

# Optimized solution
import math
K = int(eval(input()))
gcds = [math.gcd(a+1, b+1) for a in range(K) for b in range(K)]
res = sum([math.gcd(ab, c+1) for ab in gcds for c in range(K)])
print(res)
# Original solution
import math
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 += math.gcd(math.gcd(i,j), k)

print(sum)


# Optimized solution
import math
N = int(eval(input()))
 
sum = 0
for i in range(1, N+1):
    for j in range(1, N+1):
        tmp = math.gcd(i,j)
        for k in range(1, N+1):
            sum += math.gcd(tmp, k)
 
print(sum)
# Original solution
import math
import itertools
K = int(eval(input()))
 
lis = [i for i in range(1,K+1)]
a = 0
 
n = list(itertools.product(lis, repeat=3))
for i in range(len(n)):
    ma = math.gcd(math.gcd(n[i][0],n[i][1]),math.gcd(n[i][0],n[i][2]))
    a += ma
print(a)

# Optimized solution
import math
 
K = int(eval(input()))
 
lis = tuple([i for i in range(1,K+1)])
a = 0
 
for i in lis:
    for j in lis:
        i_j= math.gcd(i,j)
        for k in lis:
            i_k = math.gcd(i,k)
            i_j_k = math.gcd(i_j,i_k)
            a += i_j_k
print(a)
# 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


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

from itertools import product
from functools import reduce

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


a = eval(input())
a = int(a)
count = 0
l = list(range(1, a + 1))
m = list(range(1, a + 1))
n = list(range(1, a + 1))

for x, y, z in product(l, m, n):
            count +=  gcd(x, y, z)

print(count)

# Optimized solution
import math


a = eval(input())
a = int(a)
count = 0
for l in range(1, a + 1):
    for m in range(1, a + 1):
        x = math.gcd(l, m)
        for n in range(1, a + 1):
            count += math.gcd(x,n)

print(count)
# Original 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)

# 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):
        a = gcd(i, j)
        for k in range(1, K+1):
            ans += gcd(a, k)
print(ans)
# Original solution
import sys
# sys.stdin = open('input.txt')

from math import gcd


def triple_gcd(x, y, z):
    return gcd(gcd(x, y), z)


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 += triple_gcd(i, j, k)

print(ans)

# Optimized solution
import sys
# sys.stdin = open('input.txt')

from math import gcd


k = int(eval(input()))
ans = 0
memory = {}

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

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

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

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

# Optimized solution
import math

K = int(eval(input()))
arr = []
a = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    arr.append(math.gcd(i, j))      
for j in range(len(arr)):
  for k in range(1,K+1):
    a += math.gcd(arr[j],k)
print((int(a)))
# Original solution
import math
k=int(eval(input()))
s=0
for x in range(1,k+1):
  for y in range(1,k+1):
    for z in range(1,k+1):
      s+=math.gcd(x,math.gcd(y,z))
print(s)

# Optimized solution
import math
k=int(eval(input()))
l=[]
s=0
for x in range(1,k+1):
  for y in range(1,k+1):
    l.append(math.gcd(x,y))

for x in range(len(l)):
  for y in range(1,k+1):
    s+=math.gcd(l[x],y)
print(s)
# Original solution
import math
from functools import reduce

K = int(eval(input()))

gcd_sum = 0
target_range = list(range(1, K + 1))

for a in target_range:
  for b in target_range:
    for c in target_range:
      gcd_sum += reduce(math.gcd, (a, b, c))

print(gcd_sum)

# Optimized solution
import math
from functools import reduce
import itertools

K = int(eval(input()))

gcd_sum = 0
target_range = list(range(1, K + 1))
for comb in itertools.combinations_with_replacement(target_range, 3):
  a, b, c = comb[0], comb[1], comb[2]
  gcd = reduce(math.gcd, comb)
  
  if a == b == c:
    gcd_sum += gcd
  elif a != b != c:
    gcd_sum += gcd * 6
  else:
    gcd_sum += gcd * 3


print(gcd_sum)
# Original solution
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

# N = 200 x 200 x 200 = 8000000でO(N)で計算できることから間に合うはず
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
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

# N = 200 x 200 x 200 = 8000000でO(N)で計算できることから間に合うはず
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(k,tmp)
print(ans)
# Original solution
import math
from functools import reduce

K = int(eval(input()))

sum = 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):
            sum += gcd(i, j, k)

print(sum)


# Optimized solution
import math

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

for i in range(K):
    for j in range(K):
        tmp = math.gcd(i+1, j+1)
        for k in range(K):
            sum += math.gcd(tmp, k+1)
        
print(sum)
# Original solution
from math import gcd
from functools import reduce

K = int(eval(input()))

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

print(res)


# Optimized solution
from math import gcd

K = int(eval(input()))

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

print(res)
# Original solution
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
K = int(eval(input()))
t = 0
t1 = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for l in range(1,K+1):
            t1 = gcd(i,j)
            t = t + gcd(t1,l)
print(t)

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

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

# Optimized solution
from math import gcd

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

n=K**3
ABC=[0]*3
ans=0
for i in range(n):
    for j in range(3):
        ABC[j]=i%K+1
        i//=K
    val=math.gcd(ABC[0],ABC[1])
    val=math.gcd(val,ABC[2])
    ans+=val
print(ans)

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

ans=0
for i in range(1,K+1):
    ans+=i

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

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

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

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

for i in range(1, k+1):
    if i == 1:
        sum_ += k ** 2
    else:
        for j in range(1, k+1):
            if j == 1:
                sum_ += k
            else:
                for l in range(1, k+1):
                    if l == 1:
                        sum_ += 1
                    else:
                        sum_ += reduce(math.gcd, [i, j, l])
            
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):
        x = math.gcd(i, j)
        for l in range(1, k+1):
            sum_ += math.gcd(x, l)
            
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 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 math

K=int(eval(input()))

f=[]

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

S=0
for i in range(1,K+1):
  for j in f:
    S+=math.gcd(i,j)

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


def gcd_list(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_list([i, j, k])
print(s)


# Optimized solution
import math

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


#A,B,C=(int(x) for x in input().split())
N=int(eval(input()))
#A=list(map(int, input().split()))

l=[(a,b,c) for a in range (1,N+1) for b in range  (1, N+1) for c in range (1, N+1)]



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

i=0

for k in range(N**3):
    m=gcd_list(l[k])
    i=i+m
    
print(i)

# Optimized solution
import math

K=int(eval(input()))

total=0

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

print(total)
# Original solution
from math import gcd
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(gcd(i, j), k)
print(sum)

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

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

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