CodeEff/ECCO huggingface dataset:
# Original 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)

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

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

from math import gcd
k = int(eval(input()))
sum = 0
for a in range(k):
    for b in range(k):
        gcd_ab = gcd(a + 1, b + 1)
        for c in range(k):
            sum += gcd(gcd_ab, c + 1)
print(sum)
# Original solution
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
l=[1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199]
a=0
b=0
#for i in range(K):
#    b+=
K=int(eval(input()))
for i in range(1,K+1):
    if i in l:
        a+=K**2 +(i-1)*(K//i)**2
    else:
        for j in range(1,K+1):
            for r in range(1,K+1):
                a+=gcd(i,j,r)
print(a)

# Optimized solution
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
l=[1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199]
a=0
K=int(eval(input()))
for i in range(1,K+1):
    if i in l:
        a+=K**2 +(i-1)*(K//i)**2
    else:
        for j in range(1,K+1):
            if j in l:
                if math.gcd(i,j)==1:
                    a+=K
                else:
                    a+=(K + (math.gcd(i,j)-1)*(K//j))
            else:
                for r in range(1,K+1):
                    a+=gcd(i,j,r)
print(a)
# Original solution
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
l=[1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199]
a=0
K=int(eval(input()))
for i in range(1,K+1):
    if i in l:
        a+=K**2 +(i-1)*(K//i)**2
    else:
        for j in range(1,K+1):
            if j in l:
                if math.gcd(i,j)==1:
                    a+=K
                else:
                    a+=(K + (math.gcd(i,j)-1)*(K//j))
            else:
                for r in range(1,K+1):
                    a+=gcd(i,j,r)
print(a)

# Optimized solution
import math

a=0

K=int(eval(input()))
for i in range(1,K+1):#(1,2,3)
    for j in range(i,K+1):
        for r in range(j,K+1):
            if i==j and i==r:#(1,1,1)のような場合
                a+=math.gcd(i,math.gcd(j,r))
            elif i==j or j==r:#(1,1,2),(1,2,2)のような場合。各3通り
                a+=math.gcd(i,math.gcd(j,r))*3
            else:
                a+=math.gcd(i,math.gcd(j,r))*6
print(a)
# Original solution
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans = 0
N = int(eval(input()))
L = []
for x in range(1,N+1):
    for y in range(1,N+1):
       if(x == y):
           L.append(x)
       elif(x % y == 0):
           L.append(y)
       elif(y % x == 0):
           L.append(x)
       else:
           L.append(gcd(x,y))
for x in L:
    for z in range(1,N+1):
       if(x == z):
           ans += x 
       elif(x % z == 0):
           ans += z
       elif(z % x == 0):
           ans += x
       else:
           ans += gcd(x,z)
print(ans) 

# Optimized solution
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans = 0
N = int(eval(input()))
L = []
s_dict = {}
for x in range(1,N+1):
    for y in range(1,N+1):
       if(x == y):
           L.append(x)
           s_dict[(x,y)] = x
       elif(x % y == 0):
           L.append(y)
           s_dict[(x,y)] = y
       elif(y % x == 0):
           L.append(x)
           s_dict[(x,y)] = x
       else:
           tmp = gcd(x,y)
           L.append(tmp)
           s_dict[(x,y)] = tmp

for x in L:
    for z in range(1,N+1):
        ans += s_dict[(x,z)]
        
print(ans)
# Original solution
from math import gcd
k=int(eval(input()))
cnt=0
for i in range(1,k+1):
  for j in range(1,k+1):
    a=gcd(i,j)
    for k in range(1,k+1):
      cnt+=gcd(a,k)
print(cnt)


# Optimized solution
k=int(eval(input()))
n=3
mod=10**9+7
lst=[0]*(k+1)
ans=0

for i in range(k,0,-1):
  lst[i]+=pow(k//i,n,mod)
  if k//i==1:
    continue
  else:
    for j in range(2,k//i+1):
      lst[i]-=lst[i*j]
      
for i in range(1,k+1):
  ans+=(i*lst[i])%mod
  ans%=mod
  
print(ans)
# Original solution
import math
from functools import reduce

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

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

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

print(x)

# Optimized solution
from math import gcd

k = int(eval(input()))

r = list(range(1, k + 1))
ans = sum([gcd(gcd(a, b), c) for a in r for b in r for c in r])
print(ans)
# Original solution
import math
from functools import reduce

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

x=0
k=int(eval(input()))
r = list(range(1, k + 1))
x = sum([gcd(a, b, c) for a in r for b in r for c in r])
print(x)


# Optimized solution
import math
from functools import reduce

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

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

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

print(x)
# Original solution
import fractions
from functools import reduce
import itertools
import math

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

K = int(eval(input()))

if K == 1:
    ans = 1
elif K == 2:
    ans = 9
else:
    ans = 0
    for i in range(1, K+1):
        ans += i
        for j in range(i+1, K+1):
            ans += gcd(i, j) * 6
            for k in range(j+1, K+1):
                ans += gcd(i, j, k) * 6

print(ans)


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

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

K = int(eval(input()))

if K == 1:
    ans = 1
elif K == 2:
    ans = 9
else:
    ans = 0
    for i in range(1, K+1):
        ans += i
        for j in range(i+1, K+1):
            ans += gcd(i, j) * 6
            for k in range(j+1, K+1):
                ans += gcd(i, j, k) * 6

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

d = [[] for _ in range(k)]
for i in range(1, k+1):
    for ii in range(1, k+1):
        if i % ii == 0:
            d[i-1].append(ii)

ans = 0
for a1 in range(k):
    for a2 in range(k):
        for a3 in range(k):
            ans += max(set(d[a1]) & set(d[a2]) & set(d[a3]))

print(ans)

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

d = [[] for _ in range(k)]
for i in range(1, k+1):
    for ii in range(1, k+1):
        if i % ii == 0:
            d[i-1].append(ii)

seq = [i for i in range(1, k+1)]
ans = 0
A = list(itertools.combinations_with_replacement(seq, 3))
for a in A:
    a1 = a[0]
    a2 = a[1]
    a3 = a[2]
    if a1 == a2 == a3:
        m = 1
    elif a1 == a2 or a1 == a3 or a2 == a3:
        m = 3
    else:
        m = 6
    ans += max(set(d[a1-1]) & set(d[a2-1]) & set(d[a3-1])) * m

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

d = [[] for _ in range(k)]
for i in range(1, k+1):
    for ii in range(1, k+1):
        if i % ii == 0:
            d[i-1].append(ii)

seq = [i for i in range(1, k+1)]
ans = 0
A = list(itertools.combinations_with_replacement(seq, 3))
for a in A:
    a1 = a[0]
    a2 = a[1]
    a3 = a[2]
    if a1 == a2 == a3:
        m = 1
    elif a1 == a2 or a1 == a3 or a2 == a3:
        m = 3
    else:
        m = 6
    ans += max(set(d[a1-1]) & set(d[a2-1]) & set(d[a3-1])) * m

print(ans)

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

d = [[] for _ in range(k)]

for i in range(1, k+1):
    n = 1
    while i*n <= k:
        d[i*n-1].append(i)
        n += 1

seq = [i for i in range(1, k+1)]
ans = 0
A = list(itertools.combinations_with_replacement(seq, 3))
for a in A:
    a1 = a[0]
    a2 = a[1]
    a3 = a[2]
    if a1 == a2 == a3:
        m = 1
    elif a1 == a2 or a1 == a3 or a2 == a3:
        m = 3
    else:
        m = 6
    ans += max(set(d[a1-1]) & set(d[a2-1]) & set(d[a3-1])) * m

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

print(ans)


# Optimized solution
import math
 
w = 0
k = int(eval(input()))
for i in range(1, k+1):
    for j in range(1, k+1):
        m = math.gcd(i, j)
        for l in range(1, k+1):
            w += math.gcd(m, l)
print(w)
# Original solution
def gud(a,b):
  if a%b==0:
    return b
  else:
    return gud(b,a%b)
a=int(eval(input()))
ans=0
for i in range(a):
  for j in range(a):
    n=gud(i+1,j+1)
    for k in range(a):
      ans+=gud(n,k+1)
print(ans)

# Optimized solution
import math
def gud(a,b):
  if a%b==0:
    return b
  else:
    return gud(b,a%b)
a=int(eval(input()))
ans=0
for i in range(1,a+1):
  for j in range(1,a+1):
    n=math.gcd(i,j)
    for k in range(1,a+1):
      ans+=math.gcd(n,k)
print(ans)
# Original solution
from itertools import product
from math import gcd

k = int(eval(input()))

res = 0
for a, b, c in product(list(range(1, k+1)), repeat=3):
    res += gcd(gcd(a, b), c)

print(res)


# Optimized solution
from math import gcd

k = int(eval(input()))

res = 0
mul = [0, 1, 3, 6]
for a in range(1, k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            res += gcd(gcd(a, b), c) * mul[len({a, b, c})]

print(res)
# Original solution
import sys
import math

input = sys.stdin.readline

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

print(ans)

# Optimized solution
import sys
import math

input = sys.stdin.readline

K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
    for j in range(i, K + 1):
        n = math.gcd(i, j)
        for l in range(j, K + 1):
            if len(set([i, j, l])) == 1:
                ans += math.gcd(n, l)
            elif len(set([i, j, l])) == 2:
                ans += (math.gcd(n, l) * 3)
            else:
                ans += (math.gcd(n, l) * 6)

print(ans)
# Original solution
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
ans=0
k=int(eval(input()))
for x in range(1,k+1):
    for y in range(1,k+1):
        for z in range(1,k+1):
            ans+=gcd(x,gcd(y,z))
print(ans)

# Optimized solution
from math import gcd
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):
      ans+=gcd(l,gcd(m,n))
print(ans)
# Original solution
import math
from functools import reduce

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

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


# Optimized solution
import math
from functools import reduce

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

sum = 0
for i in range(1,n+1):
  for j in range(i,n+1):
    for k in range(j,n+1):
#      print(i, j, k)
      if i ==j and i == k:
        sum += gcd(i, j, k)
      elif i == j or j == k or i == k:
        sum += gcd(i, j, k)*3
      else: 
        sum += gcd(i, j, k)*6
#      print(sum)
print(sum)
# Original solution
from functools import reduce
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def gcd(a, b):
    """
    return gcd of a,b
    ユークリッド
    """
    while b:
        a, b = b, a % b
    return a


def list_gcd(l):
    """
    l: list
    l のgcd を返す
    """
    return reduce(gcd, l)

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+=list_gcd([i,j,k])
print(ans)



# Optimized solution

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def gcd(a, b):
    """
    return gcd of a,b
    ユークリッド
    """
    a,b =max(a,b),min(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):
        i_j = gcd(i,j)
        for k in range(1,K+1):
            ans+=gcd(i_j,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)


n = int(eval(input()))

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

print(result)


# Optimized solution
from math import gcd

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

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

print(ans)
# Original solution

K=int(eval(input()))

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

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


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

# Optimized solution
a=int(eval(input()))
import math
print((sum(math.gcd(math.gcd(i,j),k)for i in range(1,a+1) for j in range(1,a+1) for k in range(1,a+1))))
# Original solution
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import math
from functools import lru_cache


@lru_cache(maxsize=None)
def get_gcd(a, b):
    return math.gcd(a, b)


def main():
    k = int(input().strip())
    sum = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            a_, b_ = (a, b) if a < b else (b, a)
            a_b_ = get_gcd(a_, b_)
            for c in range(1, k + 1):
                sum += get_gcd(a_b_, c) if a_b_ < c else get_gcd(c, a_b_)
    print(sum)


if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import math
from functools import lru_cache

# prime_200 = {
#     2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
#     73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
#     179, 181, 191, 193, 197, 199
# }

@lru_cache(maxsize=None)
def get_gcd(a, b):
    return math.gcd(a, b)


def main():
    k = int(input().strip())
    sum = 0

    # すべて同じ(a, a, a)
    sum += k * (k + 1) // 2

    # 2 つ同じ（a, a, b）
    for a in range(1, k + 1):
        # if a in prime_200:
        #     sum += 3 * (k - 1)  # 自分と同じを除く分 * 3c1
        #     continue
        for b in range(1, k + 1):
            if a == b:
                continue  # 同じは除く
            # if b in prime_200:
            #     sum += 3  # b が素数なら gcd は 1 * 3c1
            #     continue
            a_, b_ = (a, b) if a < b else (b, a)
            sum += 3 * get_gcd(a_, b_)

    # 3 つ違う (a, b, c)
    for a in range(1, k + 1):
        for b in range(a + 1, k + 1):
            if a == b:
                continue
            a_b_ = get_gcd(a, b)
            for c in range(b + 1, k + 1):
                if a == c or b == c:
                    continue
                sum += 6 * get_gcd(a_b_, c)
    print(sum)


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

K = int(eval(input()))


def gcd3(a, b, c):
    d = math.gcd(a, b)
    e = math.gcd(d, c)
    return e


ans = 0
for x in range(1, K + 1, 1):
    for y in range(1, K + 1, 1):
        ans = ans + sum(list([gcd3(x, y, z) for z in range(1, K+1, 1)]))

print(ans)


# Optimized solution
import math

K = int(eval(input()))

ans = 0
for x in range(1, K + 1, 1):
    for y in range(1, K + 1, 1):
        ans = ans + sum(list([math.gcd(math.gcd(x, y), z) for z in range(1, K+1, 1)]))

print(ans)
# Original solution
from math import factorial

from sys import stdin


def gcd(x, y):
    if x % y == 0:
        return y
    return gcd(y, x % y)


def main():
    k = int(stdin.readline())

    ans = 0

    for a in range(1, k + 1):
        for b in range(a, k + 1):
            d = gcd(a, b)
            for c in range(b, k + 1):
                e = gcd(d, c)
                ans += e * factorial(3) // factorial(3 - len(set([a, b, c])) + 1)

    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
from sys import stdin


def gcd(x, y):
    if x % y == 0:
        return y
    return gcd(y, x % y)


def fact(x):
    if x == 1:
        return x
    return x * fact(x - 1)


def main():
    k = int(stdin.readline())

    ans = 0

    for a in range(1, k + 1):
        for b in range(a, k + 1):
            d = gcd(a, b)
            for c in range(b, k + 1):
                e = gcd(d, c)
                ans += e * fact(3) // fact(3 - len(set([a, b, c])) + 1)

    print(ans)


if __name__ == "__main__":
    main()
# Original solution
import itertools
import math
n = int(eval(input()))
c = itertools.product(list(range(1, n + 1)), repeat=3)
t = 0
for l in c:
    s = math.gcd(l[0], math.gcd(l[1], l[2]))
    t += s
print(t)


# Optimized solution
import itertools
import math

n = int(eval(input()))
c1 = list(range(1, n + 1))
c2 = itertools.combinations(list(range(1, n + 1)), 2)
c3 = itertools.combinations(list(range(1, n + 1)), 3)

t1 = sum(list(c1))
t2 = sum(list([math.gcd(x[0], x[1]) for x in c2])) * 6
t3 = sum(list([math.gcd(x[0], math.gcd(x[1], x[2])) for x in c3])) * 6

print((sum([t1, t2, t3])))
# Original solution
import itertools
import math

n = int(eval(input()))
c1 = list(range(1, n + 1))
c2 = itertools.combinations(list(range(1, n + 1)), 2)
c3 = itertools.combinations(list(range(1, n + 1)), 3)

t1 = sum(list(c1))
t2 = sum(list([math.gcd(x[0], x[1]) for x in c2])) * 6
t3 = sum(list([math.gcd(x[0], math.gcd(x[1], x[2])) for x in c3])) * 6

print((sum([t1, t2, t3])))


# Optimized solution
k, = (int(x) for x in input().split())
 
n = 3
c = {} 
t = 0
for x in range(k, 0, -1):
    c[x] = (k // x) ** n
    c[x] = c[x] - sum(c[x * y] for y in range(2, k // x + 1))
    s = c[x] * x
    t += s
    # t = t % 1000000007
 
print(t)
# Original solution
K = int(eval(input()))
total = 0

def gcd(a, b):
    if(a > b):
        a, b = b, a

    while(b > 0):
        r = a % b
        a = b
        b = r

    return a


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


print(total)

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

def gcd(a, b):
    if(a > b):
        a, b = b, a

    while(b > 0):
        r = a % b
        a = b
        b = r

    return a

dp = [[0 for i in range(K+1)] for j in range(K+1)]

for a in range(1, K+1):
    for b in range(1, K+1):
        if(dp[a][b] == 0):
            dp[a][b] = gcd(a, b)

        res = dp[a][b]

        for c in range(1, K+1):
            if(dp[res][c] == 0):
                dp[res][c] = gcd(res, c)

            total += dp[res][c]


print(total)
# Original solution
K = int(eval(input()))
total = 0
 
def gcd(a, b):
    if(a > b):
        a, b = b, a
 
    while(b > 0):
        r = a % b
        a = b
        b = r
 
    return a
 
 
for a in range(1, K+1):
    for b in range(1, K+1):
        res = gcd(a, b)
        for c in range(1, K+1):
           total += gcd(res, c)
 
 
print(total)

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

def gcd(a, b):
    if(a > b):
        a, b = b, a

    while(b > 0):
        r = a % b
        a = b
        b = r

    return a

dp = [[0 for i in range(K+1)] for j in range(K+1)]

for a in range(1, K+1):
    for b in range(1, K+1):
        if(dp[a][b] == 0):
            dp[a][b] = gcd(a, b)

        res = dp[a][b]

        for c in range(1, K+1):
            if(dp[res][c] == 0):
                dp[res][c] = gcd(res, c)

            total += dp[res][c]


print(total)
# Original solution
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
s = 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):
      s += gcd(i,j,k)
print(s)

# Optimized solution
import math
n = int(eval(input()))
sum = 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):
      sum += math.gcd(g,k)
print(sum)
# Original solution
import math
n = int(eval(input()))
sum = 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):
      sum += math.gcd(g,k)
print(sum)

# Optimized solution
import math
def main():
  n = int(eval(input()))
  sum = 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):
        sum += math.gcd(g,k)
  print(sum)

if __name__ == "__main__":
  main()
# Original solution
import sys
import math
readline = sys.stdin.readline


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


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


if __name__ == '__main__':
    main()


# Optimized solution
import sys
import math
import time
readline = sys.stdin.readline


def main():
    listSum = [1, 3, 6]
    k = int(eval(input()))
    sumGCD = 0
    for a in range(1, k + 1):
        for b in range(a, k + 1):
            for c in range(b, k + 1):
                sumGCD += gcd(a, b, c) * listSum[len(set([a, b, c])) - 1]
    print(sumGCD)


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


if __name__ == '__main__':
    s = time.time()
    main()
    # print(time.time() - s)
# Original solution
from sys import stdin
# import sys

# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
# A,B = [int(x) for x in stdin.readline().rstrip().split()]
# U = input().split()
# A, B = [str(x) for x in stdin.readline().rstrip().split()]


import math
from functools import reduce


def gcd_list(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_list([a, b, c])
print(ans)


# Optimized solution
from sys import stdin
# import sys

# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
# A,B = [int(x) for x in stdin.readline().rstrip().split()]
# U = input().split()
# A, B = [str(x) for x in stdin.readline().rstrip().split()]

import math

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