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

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

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

print(ans)

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

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

print(ans)
# Original solution
from functools import lru_cache

N = int(eval(input()))

@lru_cache(maxsize=None)
def gcd2(a, b):
  while b != 0:
    a, b = b, a % b
  return a

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

res = 0

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

print(res)


# Optimized solution
from functools import lru_cache

N = int(eval(input()))

@lru_cache(maxsize=None)
def gcd2(a, b):
  while b != 0:
    a, b = b, a % b
  return a

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

res = 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 == k:
        res += gcd(k, j, i)
      elif i != j != k:
        res += gcd(k, j, i) * 6
      else:
        res += gcd(k, j, i) * 3

print(res)
# Original solution
import math
K = int(eval(input()))
sumval = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            f = math.gcd(a,b)
            g = math.gcd(f,c)
            sumval += g
print(sumval)

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

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

K = int(eval(input()))

def GCD(x):
    return reduce(math.gcd, x)

s = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for h in range(1,K + 1):
            s += GCD((i, j, h))

print(s)

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

K = int(eval(input()))

def GCD(x):
    return reduce(math.gcd, x)

s = 0

for x in combinations_with_replacement(list(range(1, K + 1)), 3):
    if x[0] == x[1] == x[2]:
        s += GCD(x)
    elif x[0] == x[1] or x[1] == x[2] or x[0] == x[2]:
        s += GCD(x) * 3
    else:
        s += GCD(x) * 6

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 i in range(K)] for j in range(K)]
answ=0
for i in range(1,K+1):
    for j in range(1,K+1):
        ans[i-1][j-1]+=gcd(i,j)

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            answ+=gcd(ans[i-1][j-1],k)
print(answ)

# Optimized solution
import math
k = int(eval(input()))
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcd1 = math.gcd(i, j)
        for l in range(1, k + 1):
            gcd2 = math.gcd(gcd1, l)
            ans += gcd2
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
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(a,K+1):
        for c in range(b,K+1):
            if a == b == c:
                sum += gcd(a,b,c)
            elif a == b or b == c:
                sum += gcd(a,b,c) * 3
            else:
                sum += gcd(a,b,c) * 6
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
from math import gcd

k = int(eval(input()))

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

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

# Optimized solution
import math
N = int(eval(input()))
f = 0
for a in range(1, N+1):
    for b in range(1, N+1):
        for c in range(1, N+1):
            if b<a or c<a or b>c:
                continue
            elif a==b and b==c:
                d=math.gcd(a, b)
                e=math.gcd(d, c)
                f+=e
                continue
            elif a==b and b!=c:
                d=math.gcd(a, b)
                e=math.gcd(d, c)
                f+=e*3
                continue
            elif b==c and b!=a:
                d=math.gcd(a, b)
                e=math.gcd(d, c)
                f+=e*3
                continue   
            elif a==c and b!=c:
                d=math.gcd(a, b)
                e=math.gcd(d, c)
                f+=e*3
                continue
            else:
                d=math.gcd(a, b)
                e=math.gcd(d, c)
                f+=e*6
                continue
print(f)
# Original solution
import math
from functools import reduce

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

k=int(eval(input()))
ml=[i for i in range(k+1)]
n=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            if i==j==l:
                continue
            n+=gcd(i,j,l)         
print((n+sum(ml)))

# Optimized solution
from math import gcd
 
K=int(eval(input()))
 
S=0
for a in range(1,K+1):
    for b in range(1,K+1):
        calc=gcd(a,b)
        for c in range(1,K+1):
                S+=gcd(calc,c)
 
print(S)
# Original solution
import math
from functools import reduce

# reduce(function, iterable, initializer)
def gcd(*number):
    return reduce(math.gcd, number)

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

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

print(sum)


# Optimized solution
import math
from functools import reduce

# reduce(function, iterable, initializer)
def gcd(*number):
    return reduce(math.gcd, number)

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

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

if __name__ == "__main__":
    main()
# Original solution
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):
            for i in range(1,min(a,b,c)+1):
                if a%i == b%i == c%i == 0:
                    tcnt = i
            cnt += tcnt
print(cnt)

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

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 i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            ans += math.gcd(math.gcd(i,j),k)

print(ans)

# Optimized solution
from math import gcd

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

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

print(total)


# Optimized solution
import collections

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

k=int(eval(input()))
cnt=collections.defaultdict(int)
for i in range(1,k+1): #すべての(a,b)の組についてgcd(a,b)を求め、その値の個数を数える
 for j in range(1,k+1):
   cnt[gcd(i,j)]+=1
ans=0
for i in range(1,k+1): #すべてのcについて、上で求めたgcd(a,b)のあり得る値とのgcdを求め、答えに足し合わせる
 for key in list(cnt.keys()):
   ans+=gcd(i,key)*cnt[key]
print(ans)
# Original solution
import sys
import math

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


# Optimized solution
import sys
import math

N = int(eval(input()))

ans = 0
for i in range (1,N+1):
    for j in range (1,i+1):
        for k in range (1,j+1):
            if i == j == k:
                ans += math.gcd(math.gcd(i,j),k)
            elif i == j or j== k:
                ans += 3*math.gcd(math.gcd(i,j),k)
            else:
                ans += 6*math.gcd(math.gcd(i,j),k)
            #print(i,j,k)
         
            
print(ans)
# Original solution
# -*- conding: utf-8 -*-
import itertools
import math
K = int(eval(input()))

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

ans = 0
for x in list(itertools.product(list(range(1, K+1)), repeat=3)):
  # xに対して最大公約数を求める
  ans += gcd(gcd(x[0], x[1]), x[2])
print(ans)

# Optimized solution
# -*- conding: utf-8 -*-
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
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
from functools import reduce

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

comb_count = {1:1, 2:3, 3:6}
k = int(eval(input()))
ans = 0
for a in range(1, k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            ans += gcd(a, b, c) * comb_count[len(set([a, b, c]))]
print(ans)
# Original solution
import math
from functools import reduce

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

comb_count = {1:1, 2:3, 3:6}
k = int(eval(input()))
ans = 0
for a in range(1, k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            ans += gcd(a, b, c) * comb_count[len(set([a, b, c]))]
print(ans)

# Optimized solution
from collections import defaultdict

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

gcd_cnt = defaultdict(int)
ans = 0
k = int(eval(input()))
for a in range(1, k+1):
    for b in range(1, k+1):
        gcd_cnt[gcd(a, b)] += 1

for key in gcd_cnt:
    for c in range(1, k+1):
        ans += gcd(c, key) * gcd_cnt[key]
print(ans)
# Original solution
import math


n = int(eval(input()))


c = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            temp = math.gcd(i+1,j+1)
            c += math.gcd(temp,k+1)

print(c)

# Optimized solution
import math
# from functools import reduce
# from fractions import gcd
def main():
    n = int(eval(input()))
    # def gcd(*numbers):
    #     return reduce(math.gcd, numbers)

    c = 0
    for i in range(n):
        for j in range(n):
            for k in range(n):
                temp = math.gcd(i+1,j+1)
                c += math.gcd(temp,k+1)

    print(c)

main()
# Original solution
from math import gcd

k = int(eval(input()))
d = {}

ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            if (a, b, c) in d:
                ans += d[(a, b, c)]
            else:
                d[(a, b, c)] = gcd(a, gcd(b, c))
                ans += d[(a, b, c)]

print(ans)


# Optimized solution
def GCD(a, b):
    return a if b == 0 else GCD(b, a % b)


k = int(eval(input()))

ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        ab = GCD(a, b)
        if ab == 1:
            ans += k
            continue
        for c in range(1, k + 1):
            ans += GCD(ab, c)

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

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

map_list = [[0 for i in range(k+1)]for j in range(k+1)]
for i in range(1,k+1):
    for j in range(1,k+1):
        map_list[i][j]=math.gcd(i,j)

ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        gcd1 = map_list[i][j]
        for k in range(1,k+1):
            ans+=map_list[k][gcd1]
print(ans)
# Original solution
from math import gcd
from functools import reduce
def gcds(*numbers):
  return reduce(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 += gcds(a, b, c)
print(ans)

# Optimized solution
from math import gcd
from functools import reduce
def gcds(*numbers):
  return reduce(gcd, numbers)
K = int(eval(input()))
ans1 = 0
ans2 = 0
ans3 = 0
for a in range(1, K + 1):
  for b in range(a, K + 1):
    for c in range(b, K + 1):
      if a == b and b == c:
        ans1 += gcds(a, b, c)
      elif a == b or b == c or c == a:
        ans2 += gcds(a, b, c)
      else:
        ans3 += gcds(a, b, c)
print((ans1 + 3 * ans2 + 6 * ans3))
# Original solution
import math
from functools import reduce

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

n = int(eval(input()))

total = 0

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

print(total)

# Optimized solution
import math
import sys

def main():
    n = int(sys.stdin.readline())

    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)

main()
# 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):
        s=gcd(i,j)
        for k in range(1,K+1):
            S += gcd(s,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):
        s=math.gcd(i,j)
        for k in range(1,K+1):
            S += math.gcd(s,k)

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

# Optimized solution
import math
N=int(eval(input()))
g1=[math.gcd(x,y) for x in range(1,N+1) for y in range(1,N+1)]
g2=[math.gcd(x,y) for x in g1 for y in range(1,N+1)]
print((sum(g2)))
# Original solution
N = int(eval(input())) + 1

Answer = 0

def getGCD(a,b,c):
    if a == b and b == c:
        d = 1
    elif a == b or b == c or c == a:
        d = 3
    else:
        d = 6
        
    surplus = a % c
    while surplus != 0:
        a = int(c)
        c = int(surplus)
        surplus = a % c
    surplus = b % c
    while surplus != 0:
        b = int(c)
        c = int(surplus)
        surplus = b % c
    return c * d


for i in range(1,N):
    for j in range(i,N):
        for k in range(j,N):
            Answer += getGCD(k,j,i)
            
print(Answer)


# Optimized solution
N = int(eval(input())) + 1

Answer = 0

def getGCD(a,b,c):
    if a == b == c:
        d = 1
    elif a == b or b == c:
        d = 3
    else:
        d = 6
        
    surplus = a % c
    while surplus != 0:
        a,c = c,surplus
        surplus = a % c
    surplus = b % c
    while surplus != 0:
        b,c = c,surplus
        surplus = b % c
    return c * d


for i in range(1,N):
    for j in range(i,N):
        for k in range(j,N):
            Answer += getGCD(k,j,i)
            
print(Answer)
# Original solution
import math

import math
from functools import reduce

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

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

# Optimized solution
import math

m = int(eval(input()))
a = (m * (m + 1)) // 2
b = 0
c = 0
for i in range(m):
    for j in range(i + 1, m):
        b += math.gcd(i + 1, j + 1)
for i in range(m):
    for j in range(i + 1, m):
        l = math.gcd(i + 1, j + 1)
        for k in range(j + 1, m):
            c += math.gcd(l, k + 1)
print((a + b * 6 + c * 6))
# Original solution
from math import gcd
from itertools import product

K = int(eval(input()))
n = list(range(1, K+1))
total = 0

for a,b,c in product(n,repeat=3):
    d = gcd(a,b)
    e = gcd(d,c)
    total += e

print(total)

# Optimized solution
from math import gcd
from itertools import combinations_with_replacement as cwr

K = int(eval(input()))
n = list(range(1, K+1))
total = 0

for a,b,c in cwr(n,3):
    d = gcd(gcd(a,b),c)
    if a == b == c:
        total += d
    elif a != b != c:
        total += d*6
    else:
        total += d*3

print(total)
# Original solution
k = int(eval(input()))
# a,bの最大公約数


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


gcdl = [[0]*k*2 for _ in range(k*2)]
for a in range(1, k+1):
    for b in range(1, k+1):
        gcdl[a][b] = gcd(a, b)

ansl = [[[-1]*k*2 for _ in range(k*2)] for _ in range(k*2)]
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            if ansl[a][b][c] == -1:
                t = gcd(c, gcdl[a][b])
                ansl[a][b][c] = t
                ansl[a][c][b] = t
                ansl[b][a][c] = t
                ansl[b][c][a] = t
                ansl[c][b][a] = t
                ansl[c][a][b] = t
            else:
                t = ansl[a][b][c]
            ans += t
print(ans)


# Optimized solution
k = int(eval(input()))
# a,bの最大公約数


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


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


ans = 0
K = int(eval(input()))
dp = [[1] * 220 for i in range(220)] 
for i in range(1,K+1):
    for j in range(1,K+1):
        dp[i][j] = math.gcd(i,j)
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            a = dp[i][j]
            gcd = dp[a][k]
            if i == j == k:
                ans += gcd
            elif i != j != k:
                ans += gcd * 6
            else:
                ans += gcd * 3  
print(ans)


# Optimized solution
def gcd(n, m):
    # 最大公約数
    a = max(n,m)
    b = min(n,m)
    while b:
        a, b = b, a % b
    return a
ans = 0
K = int(eval(input()))
dp = [[1] * 220 for i in range(220)] 
for i in range(1,K+1):
    for j in range(1,K+1):
        dp[i][j] = gcd(i,j)
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            a = dp[i][j]
            gcd = dp[a][k]
            if i == j == k:
                ans += gcd
            elif i != j != k:
                ans += gcd * 6
            else:
                ans += gcd * 3  
print(ans)
# Original solution
import math
k=int(eval(input()))
total=0
info=[0]
for i in range(1,201):
    for j in range(1,201):
        if j<i:
            info.append(0)
            continue
        info.append(math.gcd(i,j))
        #print(str(i)+" "+str(j)+" "+str(math.gcd(i,j)))
#print(info[202])
#print(info)
for i in range(1,k+1):
    a=[]
    a.append(i)
    for j in range(1,k+1):
        a.append(j)
        for m in range(1,k+1):
            a.append(m)
            a=sorted(a)
            gcd=info[(a[0]-1)*200+a[1]]
            b=min(gcd,a[2])
            c=max(gcd,a[2])
            gcd=info[(b-1)*200+c]
            total+=gcd
            #print(gcd)
            #print(a)
            a=[i,j]
        a=[i]
print(total)

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

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

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

ans = 0
if n == 1:
    ans = 1
else:
    for i in range(n):
        i = i + 1
        #ans = ans + i #(i,i,i)
        for j in range(n):
            j = j + 1
            for k in range(n):
                k = k + 1
                ij = gcd(i,j)
                ans = ans + gcd(ij,k)

print(ans)

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

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

ans = 0
if n == 1:
    ans = 1
else:
    for i in range(n):
        i = i + 1
        for j in range(n):
            j = j + 1
            for k in range(n):
                k = k + 1
                ij = gcd(i,j)
                ans = ans + gcd(ij,k)

print(ans)
# Original solution
import math

k = int(eval(input()))

wa = 0

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


print(wa)

# Optimized solution
from math import gcd

k = int(eval(input()))

wa = 0

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


print(wa)