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


def gcd_kai(*numbers):
    return reduce(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_kai(i + 1, j + 1, k + 1)
print(ans)


# Optimized solution
from math import gcd
from functools import reduce


def gcd_kai(*numbers):
    return reduce(gcd, numbers)


K = int(eval(input()))
ans = 1
if K == 1:
    next
else:
    ans += (K - 1) * K * 3
    ans_sub = 0
    for i in range(2, K):
        for j in range(i + 1, K + 1):
            for k in range(i, K + 1):
                ans_sub += gcd_kai(i, j, k)
    ans += ans_sub * 3
    for i in range(2, K + 1):
        ans += i
print(ans)
# Original solution
import math
N = int(eval(input()))
#sum_ = 1+N
sum_ = 0
for i in range(1, 1+N):
    for j in range(1, 1+N):
        for k in range(1, 1+N):
            a = math.gcd(i, j)
            sum_ += math.gcd(a, k)
            
print(sum_)

# Optimized solution
import math
N = int(eval(input()))
#sum_ = 1+N
sum_ = 0
for i in range(1, 1+N):
    for j in range(1, 1+N):
        a = math.gcd(i, j)
        for k in range(1, 1+N):
            sum_ += math.gcd(a, k)
            
print(sum_)
# Original solution
import math
from functools import reduce
import itertools
k=int(eval(input()))
def gcd(*numbers):
    return reduce(math.gcd,numbers)
ans=0
for i,j,m in itertools.product(list(range(1,k+1)),list(range(1,k+1)),list(range(1,k+1))):
    ans+=gcd(i,j,m)
print(ans)

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

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

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

for a in range(1, k+1):
    for b in range(1, k+1):
        if math.gcd(a, b) not in dec:
            dec[math.gcd(a,b)] = 1
        else:
            dec[math.gcd(a,b)] += 1
ans = 0
for c in range(1, k+1):
    for d in list(dec.keys()):
        ans += math.gcd(d, c) * dec[d]
print(ans)
# Original solution
import sys
input = sys.stdin.readline
from itertools import *
from functools import *
from collections import *
from heapq import heapify, heappop, heappush, heappushpop

from math import gcd
    
INF = float('inf')
NIL = - 1

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




# Optimized solution
import sys
input = sys.stdin.readline
from itertools import *
from functools import *
from collections import *
from heapq import heapify, heappop, heappush, heappushpop

from math import gcd

INF = float('inf')
NIL = - 1

N = int(eval(input()))
ans = 0
for i in range(1, N + 1):
    if i == 1:
        ans += N ** 2
        continue
    for j in range(1, N + 1):
        if j == 1:
            ans += N
            continue
        tmp = gcd(i, j)
        for k in range(1, N + 1):
            ans += gcd(tmp, k)
print(ans)
# Original solution
K=int(eval(input()))

Ans=0
import math

for i in range(K):
    for j in range(K):
        for k in range(K):
            temp=math.gcd(i+1,j+1)
            Ans+=math.gcd(temp,k+1)

print(Ans)


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

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

Ans=0
from math import gcd
for i in range(1,K):
    for j in range(1,K):
        tempA=gcd(i,j)
        for k in range(K-1):
            Ans+=gcd(tempA,k+1)
            
print(Ans)


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

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

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

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

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

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

# Optimized solution
import math

k = int(eval(input()))
s = 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):
            s += math.gcd(ab, c)
print(s)
# Original solution
import math 

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

for s in range(1,K+1):
    for t in range(1,K+1):
        for u in range(1,K+1):
            # print(s,t,u,math.gcd(math.gcd(s,t),u))
            total +=math.gcd(math.gcd(s,t),u)
2
print(total)


# Optimized solution
import math 

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

for s in range(1,K+1):
    for t in range(1,K+1):
        alpha = math.gcd(s,t)
        if alpha == 1:
            total += K
            continue
        for u in range(1,K+1):
            # print(s,t,u,math.gcd(alpha,u))
            total +=math.gcd(alpha,u)

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

import math
from functools import reduce

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

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
K = int(eval(input()))

from math import gcd


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

print(sum)
# Original solution
from math import gcd
from functools import lru_cache
from itertools import combinations

a = int(eval(input()))

def main():
    for i in range(1, a+1):
        for j in range(i, a+1):
            for k in range(j, a+1):
                x = len({i, j, k})
                if x == 1:
                    x = 1
                elif x == 2:
                    x = 3
                else:
                    x = 6
                yield gcd(gcd(i, j), k) * x

print((sum(main())))



# Optimized solution
from math import gcd

a = int(eval(input()))

def main():
    for i in range(1, a+1):
        for j in range(i, a+1):
            ab = gcd(i, j)
            for k in range(j, a+1):
                x = len({i, j, k})
                if x == 1:
                    x = 1
                elif x == 2:
                    x = 3
                else:
                    x = 6
                yield gcd(ab, k) * x

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

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

K = int(eval(input()))

Sum = []
for a in range(1, K+1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            gcd = gcd_list([a, b, c])
            Sum.append(gcd)

print((sum(Sum)))

# Optimized solution
import math

K = int(eval(input()))

Sum = []
for a in range(1, K+1):
    for b in range(1, K + 1):
        gcd2 = math.gcd(a, b)
        for c in range(1, K + 1):
            gcd = math.gcd(gcd2, c)
            Sum.append(gcd)

print((sum(Sum)))
# Original solution
from math import gcd
k = int(eval(input()))
s = 0
for x in range(1, k + 1):
    for y in range(1, k + 1):
        t = gcd(x, y)
        for z in range(1, k + 1):
            s += gcd(t, z)
print(s)

# Optimized solution
from math import gcd
k = int(eval(input()))
s = 0
for x in range(1, k + 1):
    for y in range(1, k + 1):
        t = gcd(x, y)
        if t == 1:
            s += k
            continue
        for z in range(1, k + 1):
            s += gcd(t, z)
print(s)
# Original solution
import math
import sys
def getN():
    return int(eval(input()))

def gcd(p, q):
    if p % q == 0: return q
    return gcd(q, p % q)

def main():
    
    K = getN()

    result = 0

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

    return

if __name__ == "__main__":
    main()

# Optimized solution
def getN():
    return int(eval(input()))

# def gcd(p, q):
#     if p % q == 0: return q
#     return gcd(q, p % q)

def gcd(p, q):
    while q != 0:
        r = p % q
        p = q
        q = r
    return p

def main():
    
    K = getN()

    result = 0

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

    return

if __name__ == "__main__":
    main()
# Original solution
import sys, os, math

def get_cd(n):
    cd = []
    for i in range(1, int(n/2)+1):
        if n % i == 0:
            cd.append(i)
        else:
            continue
    cd.append(n)
    return cd

def get_gcd(a, b, c, cd_d):
    if 1 in [a, b, c]:
        return 1
    else:
        min_v = min([a,b,c])
        cds_min = cd_d[min_v]
        gcd = 1
        cd = sorted(list(set(cd_d[a]) & set(cd_d[b]) & set(cd_d[c])))
        return cd[-1]

if __name__ == '__main__':
    k = int(eval(input()))
    cc_d = {}
    for i in range(1, k+1):
        cc_d[i] = get_cd(i)

    computed_d = {}
    s = 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:
                    s += a
                else:
                    gcd = get_gcd(a, b, c, cc_d)
                    if a != b != c:
                        s += gcd*6
                    else:
                        s += gcd*3
    print(s)

# Optimized solution
import sys, os, math

def get_cd(n):
    cd = []
    for i in range(1, int(n/2)+1):
        if n % i == 0:
            cd.append(i)
        else:
            continue
    cd.append(n)
    return cd

def get_gcd(a, b, c, cd_d):
    if 1 in [a, b, c]:
        return 1
    else:
        cd = sorted(list(set(cd_d[a]) & set(cd_d[b]) & set(cd_d[c])))
        return cd[-1]

if __name__ == '__main__':
    k = int(eval(input()))
    cc_d = {}
    for i in range(1, k+1):
        cc_d[i] = get_cd(i)

    computed_d = {}
    s = 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:
                    s += a
                else:
                    gcd = get_gcd(a, b, c, cc_d)
                    if a != b != c:
                        s += gcd*6
                    else:
                        s += gcd*3
    print(s)
# 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):
    for b in range(k):
        for c in range(k):
            # print(a+1, b+1, c+1)
            sum += gcd(a+1, b+1, c+1)

print(sum)

# Optimized solution
import math

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

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

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

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

# Optimized solution
from math import gcd

K = int(eval(input()))
ans=0
array = [0] * 201

for X in range(1,K+1):
    for c in range(1,K+1):
        array[X] += gcd(X,c)

for a in range(1,K+1):
    for b in range(1,K+1):
        X = gcd(a,b)
        ans += array[X]

print(ans)
# Original solution
k = int(eval(input()))
ans = 0
import math
import itertools
from functools import reduce

def gcd(num):
    return reduce(math.gcd, num)

numlist = list(range(1, k+1))
l = list(itertools.product(numlist, repeat=3))

ans = sum(map(gcd, l))

print(ans)

# Optimized solution
k = int(eval(input()))
ans = 0
import math
from functools import reduce

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

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
z = list(range(1, 1+int(eval(input()))))
y = 0
for a in z:
  for b in z:
    for c in z:
      y += math.gcd(math.gcd(a,b),c)
print(y)

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

def gcd2(*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 += gcd2(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
from functools import reduce

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

def main():
    K = int(eval(input()))
    l = []
    for i in range(1, K+1, 1):
        for j in range(1, K+1, 1):
            for k in range(1, K+1, 1):
                g = gcd(i, j, k)
                l.append(g)            
    print((sum(l)))
main()

# 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 l in range(1, k+1):
      ans+=gcd(gcd(i,j),l)
 
print(ans)
# Original solution
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

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

  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)
  return
  
  
#Solve
if __name__ == "__main__":
    solve()


# Optimized solution
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]
 
sys.setrecursionlimit(1000000)
mod = 1000000007
 
def solve():
    def gcd(a,b):
        if a == 0:
            return b
        return gcd(b%a, a)
    k = I()
    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)
    return
 
#Solve
if __name__ == "__main__":
    solve()
# Original solution
import math
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 += math.gcd(math.gcd(a, b), c)

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

print(sum)
# Original 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): 
        for c in range(1,k+1):
            sum += gcd(gcd(a, b), c)

print(sum)

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

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

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

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

if K==1:
  print((1))
  exit()
elif K==2:
  print((9))
  exit()
else:
  t=0
  for i in range(1,K-1):
    for j in range(i+1,K):
      for k in range(j+1,K+1):
        a=math.gcd(i,j)
        b=math.gcd(a,k)
        t+=b
  tw=0
  for i in range(1,K):
    for j in range(i+1,K+1):
      c=math.gcd(i,j)
      tw+=c
  
  on=0
  for i in range(1,K+1):
    on+=i
  print((t*6+tw*6+on))
# Original solution
k = int(eval(input()))

import math
import itertools
num_list = list(list(itertools.product(list(range(1,k+1)), repeat=3)))

sum_ = 0
for i,j,k in num_list:
    sum_ += math.gcd(i, math.gcd(j, k))
    
print(sum_)

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

# Optimized 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()))
sum=0
for a in range(1, n+1):
    for b in range(1, n+1):
        ab=math.gcd(a,b)
        for c in range(1, n+1):
#            print(list(set([a,b,c])))
#            abc=list(set([a,b,c]))
#            sum=sum+gcd_list(abc)
            abc=math.gcd(ab,c)
            sum=sum+abc
print(sum)
# Original solution
from math import gcd
import itertools

def calc(a,b,c):
    x=gcd(a,b)
    y=gcd(x,c)
    return y

n=int(eval(input()))

A=list(itertools.product(list(range(1,n+1)), repeat=3))

D={}
for i in A:
    mat=tuple(sorted(i))
    if mat in D:
        D[mat]+=1
    else:
        D[mat]=1

ans=0
for a,b,c in D:
    ans+=calc(a,b,c)*D[(a,b,c)]
print(ans)


# Optimized solution
from math import gcd
import itertools

def calc(a,b,c):
    x=gcd(a,b)
    y=gcd(x,c)
    return y

n=int(eval(input()))
A=list(itertools.combinations_with_replacement(list(range(1,n+1)), 3))

ans=0
for a,b,c in A:
    if a==b==c:
        ans+=calc(a,b,c)
    elif a!=b and a!=c and b!=c:
        ans+=calc(a,b,c)*6
    else:
        ans+=calc(a,b,c)*3
print(ans)
# Original solution
k=int(eval(input()))

import math
 
res=0
 
for n in range(1,k+1):
    for i in range(1,k+1):
        for j in range(1,k+1):

            res+=math.gcd(math.gcd(n,i),j)

print(res)

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

from math import gcd
 
res=0
 
for n in range(1,k+1):
    for i in range(1,k+1):
        for j in range(1,k+1):

            res+=gcd(gcd(n,i),j)

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

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

K = int(eval(input()))
box = []
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            box.append(gcd(a,b,c))
print((sum(box)))

# Optimized solution
import math
from functools import reduce

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

K = int(eval(input()))
box = []
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:
                box.append(gcd(a,b,c))
            elif a!=b and b!=c and c!=a:
                box.append(gcd(a,b,c)*6)
            else:
                box.append(gcd(a,b,c)*3)
print((sum(box)))
# Original solution
from math import gcd
K=int(eval(input()))
k=[1,1,1]
g=0
for a in range(1,K+1):
  for b in range(1,K+1):
    for c in range(1,K+1):
      g+=gcd(gcd(a,b),c)
      
      
print(g)

# Optimized solution
from math import gcd
K=int(eval(input()))
g=0
for a in range(1,K-1):
  for b in range(a+1,K):
    for c in range(b+1,K+1):
      g+=gcd(gcd(a,b),c)*6
for  d in range(1,K):
  for e in range(d+1,K+1):
    g+=gcd(d,e)*6
g+=K*(K+1)//2
print(g)
# Original solution
K=int(eval(input()))

import fractions,itertools
data = [i for i in range(1,K+1)]

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,b,c in itertools.product(data, repeat=3):
    ans += gcd(a,b,c)
print(ans)



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

import itertools,math
from functools import reduce

data = [i for i in range(1,K+1)]

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

ans = 0
for a,b,c in itertools.product(data, repeat=3):
    ans += gcd(a,b,c)
print(ans)
# Original solution
K=int(eval(input()))

import itertools,math
from functools import reduce

data = [i for i in range(1,K+1)]

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

ans = 0
for a,b,c in itertools.product(data, repeat=3):
    ans += gcd(a,b,c)
print(ans)



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

import math
from functools import reduce

def gcd(*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)