CodeEff/ECCO huggingface dataset:
# Original solution
from math import gcd
k=int(eval(input()))
cnt=0
for i in range(1,k+1):
  for p in range(1,k+1):
    for q in range(1,k+1):
      gcd1=gcd(i,p)
      gcd2=gcd(p,q)
      cnt+=gcd(gcd1,gcd2)

      
print(cnt)
  



# Optimized solution
from math import gcd
k=int(eval(input()))
cnt=0
for i in range(1,k+1):
  for p in range(1,k+1):
    for q in range(1,k+1):
      gcd1=gcd(i,p)
      
      cnt+=gcd(gcd1,q)

      
print(cnt)
# Original solution
import math

k = int(eval(input()))

result = 0

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

print(result)

# Optimized solution
import math
import itertools

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

for a in range(1, k+1):
  for b in range(a+1, k+1):
    for c in range(b+1, k+1):
      r = math.gcd(math.gcd(a, b), c)
      r *= 6
      result += r

for a in range(1, k+1):
  for b in range(a+1, k+1):
    r = math.gcd(a, b)
    r *= 6
    result += r
    
for a in range(1, k+1):
  result += a

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

print(s)


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

from math import gcd

s = 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):
      s += gcd(g, c)

print(s)
# Original solution
import math

k = int(eval(input()))

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

print(ans)


# Optimized solution
import math


def main():
    k = int(eval(input()))
    ans = 0
    gcd = math.gcd
    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)

main()
# Original solution
import math


def main():
    k = int(eval(input()))
    ans = 0
    gcd = math.gcd
    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)

main()

# Optimized solution
import math


def main():
    k = int(eval(input()))
    ans = 0
    gcd = math.gcd
    for i in range(1, k+1):
        for j in range(1, k+1):
            ij = gcd(i,j)
            for l in range(1, k+1):
                ans += gcd(ij, l)

    print(ans)

main()
# Original solution
import math
from functools import reduce
from itertools import product

def resolve():
  K = int(eval(input()))
  gcd = math.gcd
  step1 = [ gcd(x[0], x[1]) for x in product(list(range(1, K+1)), list(range(1, K+1))) ]
  result = sum([ gcd(x[0], x[1]) for x in product(step1, list(range(1, K+1))) ])
  print(result)

if __name__ == "__main__":
    resolve()


# 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(math.gcd(i,j), l)

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

def gcd(a,b):
  ma = max(a,b)
  mb = min(a,b)
  jy = ma % mb
  if jy == 0 :
    return mb
  else:
    return gcd(mb,jy)
sum = 0
for i in range(n):
  for j in range(n):
    for k in range(n):
      sum += gcd(i+1,gcd(j+1,k+1))

print(sum)

# Optimized solution
n = int(eval(input()))
 
def gcd(a,b):
  ma = max(a,b)
  mb = min(a,b)
  jy = ma % mb
  if jy == 0 :
    return mb
  else:
    return gcd(mb,jy)
sum = 0
for i in range(1,n+1):
  sum += i

for i in range(1,n):
  for j in range(i+1,n+1):
    sum += 6 * gcd(i,j)

for i in range(1,n-1):
  for j in range(i+1,n):
    for k in range(j+1,n+1):
      sum += 6 * gcd(i,gcd(j,k))
 
print(sum)
# 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):
      t_gcd=gcd(i,j)
      ans+=gcd(t_gcd,l)
 
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):
    for l in range(1, k+1):
      ans+=gcd(gcd(i,j),l)
 
print(ans)
# Original solution
#!/usr/bin/env python3
from functools import reduce
from itertools import product
from math import gcd

k = int(eval(input()))
p = list(product(list(range(1, k + 1)), repeat=3))
print((sum(reduce(gcd, i) for i in p)))


# Optimized solution
#!/usr/bin/env python3
from functools import reduce
from itertools import combinations
from math import gcd

K = int(eval(input()))

sum = K * (K + 1) // 2

for i in combinations(list(range(1, K + 1)), 2):
    sum += 6 * reduce(gcd, i)

for i in combinations(list(range(1, K + 1)), 3):
    sum += 6 * reduce(gcd, i)

print(sum)
# Original solution
import sys
import math
from functools import lru_cache

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


@lru_cache(maxsize=None)
def solve(x, y):
    return math.gcd(x, y)


def main():
    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):
                x = [i, j, k]
                x.sort()
                xx = solve(x[0], x[1])
                if xx > x[2]:
                    ans += solve(x[2], xx)
                else:
                    ans += solve(xx, x[2])

    print(ans)

if __name__ == '__main__':
    main()


# Optimized solution
import sys
import math
from functools import lru_cache

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


@lru_cache(maxsize=None)
def solve(x, y):
    return math.gcd(x, y)


def main():
    N = int(eval(input()))

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

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
k = int(eval(input()))
import itertools
def GCD(a,b):
    if(a%b == 0):
        return b
    else:
        return GCD(b,a%b)
total = 0
for i in list(itertools.product(list(range(1,k+1)), repeat = 3)):
    a = int(i[0])
    b = int(i[1])
    c = int(i[2])
    total += GCD(GCD(a,b),c)
print(total)

# Optimized solution
k = int(eval(input()))
import itertools
def GCD(a,b):
    if(a%b == 0):
        return b
    else:
        return GCD(b,a%b)
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)
# Original solution
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")

N = I()

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
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N = I()
 
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)
# 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):
			sum += gcd(a+1, b+1, c+1)
print(sum)

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

sum = 0
dict = {}
for a in range(K):
	for b in range(K):
		ab = math.gcd(a+1, b+1)
		if ab in dict:
			dict[ab] = dict[ab]+1 
		else:
			dict[ab] = 1
for c in range(K):
	for ab in dict:
		sum += math.gcd(ab, c+1)*dict[ab]
print(sum)
# Original solution
import math
k = int(eval(input()))
ans = 0
for a in range(k):
    for b in range(k):
        for c in range(k):
            GCDab = math.gcd(a+1, b+1)
            GCDabc = math.gcd(GCDab, c+1)
            ans += GCDabc
print(ans)

# Optimized solution
import math
k = int(eval(input()))
ansA, ansB, ansC = 0, 0, 0
for a in range(k):
    ansC += a+1
    for b in range(k-a-1):
        GCDab = math.gcd(a+1, a+b+2)
        ansB += GCDab
        for c in range(k-a-b-2):
            GCDabc = math.gcd(GCDab, a+b+c+3)
            ansA += GCDabc
ans = ansA * 6 + ansB * 6 + ansC
print(ans)
# Original solution
k=int(eval(input()))
import itertools
import math
from functools import reduce
def gcd(*numbers):
  return reduce(math.gcd, numbers)
ans=0
for i in range(1, k+1):
  for h in range (1, k+1):
    for j in range (1, k+1):
      ans+=gcd(*[i, h, j])
print(ans)

# Optimized solution
k=int(eval(input()))
l=list(range(1, k+1))
import itertools
import math
from functools import reduce
def gcd(*numbers):
  return reduce(math.gcd, numbers)
ans=0
for v in itertools.combinations_with_replacement(l, 3):
  if v[0]==v[1]==v[2]:
    ans+=gcd(*v)
  elif v[0]==v[1]:
    ans+=gcd(*v)*3
  elif v[1]==v[2]:
    ans+=gcd(*v)*3
  elif v[0]==v[2]:
    ans+=gcd(*v)*3
  else:
    ans+=gcd(*v)*6
print(ans)
# Original solution
import math
b=int(eval(input()))+1
sum=0
for x in range(1,b):
    for y in range(1,b):
        for z in range(1,b):
            if x==1 or y==1 or z==1:
                sum+=1
            elif x==y and x==z:
                sum+=x
            elif x==y or z==y:
                sum+=math.gcd(x, z)
            elif x==z:
                sum+=math.gcd(y, z)
            else:
                sum+=math.gcd(x, math.gcd(y, z))
print(sum)

# Optimized solution

b=int(eval(input()))-1
ary=[1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772,10813692]
print((ary[b]))
# Original solution
import math
from functools import reduce

k = int(eval(input()))

def gcd2(*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):
            #print(gcd2(a,b,c))
            sum = sum + gcd2(a,b,c)

print(sum)
        

# Optimized solution
import math
from functools import reduce

k = int(eval(input()))

def gcd2(*numbers):
    return reduce(math.gcd,numbers)
sum = 0
for a in range(1,k+1):
    for b in range(a,k+1):
        for c in range(b,k+1):
            if len(set([a,b,c]))==2:
                sum = sum + gcd2(a,b,c)*3
            elif len(set([a,b,c]))==1:
                sum = sum + gcd2(a,b,c)
            else:
                sum = sum + gcd2(a,b,c)*6
            #print(gcd2(a,b,c))


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

# Optimized 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(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            if i==j and j==k:
                ans=ans+gcd(i,j,k)
            elif i==j or j==k:
                ans=ans+3*gcd(i,j,k)
            else:
                ans=ans+6*gcd(i,j,k)
            
print(ans)
# Original solution
import math
#import itertools
num = (int)(eval(input()))
total = 0
#for i, j, k in itertools.product(list(range(1, num + 1)), list(range(1, num + 1)), list(range(1, num + 1))):
#  total += math.gcd(math.gcd(i, j), k)
#print(total)
for i in range(1, num + 1):
  for j in range(1, num + 1):
    for k in range(1, num + 1):
      total += math.gcd(math.gcd(i, j), k)
print(total)

# Optimized solution
import math
num = (int)(eval(input()))
total = 0

for i in range(1, num + 1):
  for j in range(1, num + 1):
    sub = math.gcd(i, j)
    for k in range(1, num + 1):
      total += math.gcd(sub, k)
print(total)
# Original solution
import itertools as it
import math

K = int(eval(input()))

gcd_list = []
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            gcd_ = math.gcd(math.gcd(i, j), k)
            gcd_list.append(gcd_)
print((sum(gcd_list)))


# Optimized solution
import itertools as it
import math

K = int(eval(input()))

itr = list(range(1, K+1))
gcd_ = sum([math.gcd(math.gcd(i, j), k)
            for i, j, k in it.product(itr, itr, itr)])
print(gcd_)
# Original solution
import itertools
import math
from functools import reduce

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

N = int(eval(input()))
List1 = []
for i in range(1,N+1):
  List1.append(i)
x = itertools.product(List1,List1,List1)
tryList= list(x)
res = 0

for i in tryList:
  res += gcd_list(i)
print(res)

# Optimized solution
import math

N = int(eval(input()))
n = 0
m = 0
res =0 
List1 = ["INF"]*(N+1)
for i in range(1,N+1):
  for j in range(1,N+1):
    n = math.gcd(i,j)
    if List1[n] == "INF":
      for k in range(1,N+1):
        m += math.gcd(n,k)
      res += m
      List1[n] = m
      m = 0
    else:
      res += List1[n]
print(res)
# Original solution
from math import gcd
K = int(eval(input()))
ret = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            ret += gcd(gcd(a,b),c)
print(ret)


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

import sys
input = sys.stdin.readline
from math import gcd

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

if __name__ == '__main__':
    main()
# Original solution
def gcd(x, y):
  while(x % y != 0 and y % x != 0):
    if(x > y):
      x = x % y
    else:
      y = y % x
  if(x > y):
    return y
  else:
    return x

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

# Optimized solution
def gcd(x, y):
  while(x % y != 0 and y % x != 0):
    if(x > y):
      x = x % y
    else:
      y = y % x
  if(x > y):
    return y
  else:
    return x

K = int(eval(input()))
ans = 0
for i in range(1, K+1):
  for j in range(i, K+1):
    for k in range(j, K+1):
      if(i == j and j == k):
        ans += i
      elif(i == j or j == k):
        ans += gcd(i, k) * 3
      else:
        ans += gcd(i, gcd(j, k)) * 6
print(ans)
# Original solution
import math
from functools import reduce


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

n=int(eval(input()))
l1=list(range(1,n+1))
l2=list(range(1,n+1))
l3=list(range(1,n+1))

count=0

for i in l1:
    for j in l2:
        for k in l3:
            count+=gcd_list([i,j,k])

print(count)

# Optimized solution
import math
from functools import reduce


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

n=int(eval(input()))
l1=list(range(1,n+1))
l2=list(range(1,n+1))
l3=list(range(1,n+1))

count=0

for i in l1:
    for j in l2:
        te=math.gcd(i,j)
        for k in l3:
            count+=math.gcd(te,k)

print(count)
# Original solution
N = int(eval(input()))
N = N+1
sum = 0

import math
from functools import reduce

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

for i in range(1, N):

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

print( sum )


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

from math import gcd

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

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

def main():
    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):
                a = [i,j,k]
                sum = sum + reduce(gcd,a)

    print(sum)

main()


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


def main():
    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):
                a = [i,j,k]
                b = len(list(set(list(itertools.permutations(a,3)))))
                sum = sum + (b*reduce(gcd,a))

    print(sum)

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

# Optimized solution
from math import gcd
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 += gcd(gcd(i,j), k)
      
print(ans)
# Original solution
n=int(eval(input()))
# a,b,c=map(int,input().split())
cnt=0
def gcd(a,b):
    if a==0: return b
    else: return gcd(b%a,a)
# print(gcd(a,b))

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

for i in range(1,n+1):
    for j in range ( 1 , n + 1 ):
        for k in range ( 1 , n + 1 ):
            # print(i,j,k)
            cnt+=gcd_3(i,j,k)
print(cnt)


# Optimized solution
def main():
    from math import gcd

    K = int(eval(input()))

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


main()
# Original solution
# -*- coding: utf-8 -*-

import math
from functools import reduce

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

k = int(eval(input()))

sum = 0
for p in range(k):
    for q in range(k):
        for r in range(k):
            sum += gcd(p + 1, q + 1, r + 1)
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 p in range(k):
    for q in range(k):
        n = math.gcd(p + 1, q + 1)
        for r in range(k):
            sum += math.gcd(n, r + 1)
print(sum)
# Original solution
import math


def gcd(a, b, c):

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


k = int(eval(input()))
answer = 0
for w_a in range(1, k + 1):
    for w_b in range(1, k + 1):
        for w_c in range(1, k + 1):
            answer += gcd(w_a, w_b, w_c)

print(answer)


# Optimized solution
import math


k = int(eval(input()))
answer = 0
for w_a in range(1, k + 1):
    for w_b in range(1, k + 1):
        w = math.gcd(w_a, w_b)
        for w_c in range(1, k + 1):
            answer += math.gcd(w, w_c)

print(answer)
# Original solution
from math import*;from itertools import*;r=list(range(1,int(eval(input()))+1));print((sum(gcd(a,gcd(b,c))for a,b,c in product(r,r,r))))

# Optimized solution
from math import*;r=list(range(1,int(eval(input()))+1));print((sum(gcd(a,gcd(b,c))for a in r for b in r for c in r)))
# Original solution
def gcd(a,b):
    if b==0: return a
    return gcd(b,a%b)

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

# Optimized solution
from math import gcd

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

k=int(eval(input()))
ans=0
for a in range(k):
    for b in range(k):
        for c in range(k):
            ans+=gcd(a+1,gcd(b+1,c+1))
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
def gcd(a,b):
    if b==0: return a
    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):
        temp=gcd(a,b)
        for c in range(1,k+1):
            ans+=gcd(temp,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):
        temp=gcd(a,b)
        for c in range(1,k+1):
            ans+=gcd(temp,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
def gcd(a, b):
  while b:
    a, b = b, a % b
  return a

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

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