CodeEff/ECCO huggingface dataset:
# Original solution
def gcd(p, q) :
	if p % q == 0 :
		return q
	else :
		return gcd(q,p%q)
if __name__ == '__main__':
	ans = 0
	tmp = 0
	k = int(eval(input()))
	for i in range(1,k+1) :
		for j in range(1, k+1) :
			tmp = gcd(i,j)
			for l in range(1, k+1) :
				ans += gcd(tmp,l)
	print(ans)


# Optimized solution
def gcd(p, q) :
	if p % q == 0 :
		return q
	else :
		return gcd(q,p%q)
if __name__ == '__main__':
	k = int(eval(input()))
	a = []
	ans = 0
	for i in range(1,k+1) :
		for j in range(1,k+1) :
			a.append(gcd(i,j))
	for i in range(1,k+1) :
		for j in a :
			ans += gcd(i,j)
	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 k in range(1, K+1):
            ans += gcd(gcd(i, j), k)
            
print(ans)

# Optimized solution
from math import *

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
import math
n = int(eval(input()))
a = 0
for i in range(0,n):
  for j in range(0,n):
    for k in range(0,n):
      gcd1 = math.gcd(i+1,j+1)
      gcd2 = math.gcd(gcd1,k+1)
      a = a + gcd2
      
print(a)

# Optimized solution
import math
n = int(eval(input()))
a = 0
for i in range(0,n):
  for j in range(0,n):
    gcd1 = math.gcd(i+1,j+1)
    
    for k in range(0,n):
      gcd2 = math.gcd(gcd1,k+1)
      a = a + gcd2
      
print(a)
# Original solution
from math import gcd

k = int(eval(input()))

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

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

print(sum)
# Original solution

def gcd(a,b):
    if a < b:
        a, b = b, a
    if mem[a][b]:
        return mem[a][b]
    if b == 0:
        return a
    mem[a][b] = gcd(b, a % b)
        
    return mem[a][b]

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


# Optimized solution
def gcd(a,b):
    if a < b:
        a, b = b, a
    if mem[a][b]:
        return mem[a][b]
    if b == 0:
        return a
    mem[a][b] = gcd(b, a % b)
    return mem[a][b]

k = int(eval(input()))
ans = 0
mem = [[0 for a in range(k+1)]for b in range(k+1)]
n = k+1
for i in range(1,n):
    for j in range(1,n):
        d = gcd(i,j)
        for k in range(1,n):
            ans += gcd(d,k)
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
import math


K = int(eval(input()))

sum = 0

for i in range(1, K + 1):
    for j in range(1, K + 1):
        sum += math.gcd(i, j)
        if j == K:
            break
        else:
            for k in range(j + 1, K + 1):
                sum += math.gcd(i, math.gcd(j, k)) * 2

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

print(ans)

# Optimized solution
import math

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

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

print(ans)
# Original solution
import math
k = int(eval(input()))
ans=0
for x in range(1,k+1):
    for y in range(1,k+1):
        for z in range(1,k+1):
            ans += math.gcd(math.gcd(x, y),z)
print(ans)

# Optimized solution
from math import gcd
k = int(eval(input()))
ans = 0
for x in range(1, k + 1):
    for y in range(1, k + 1):
        a = gcd(x, y)
        for z in range(1, k + 1):
            ans += gcd(a, z)
print(ans)
# Original solution
from math import*
r = list(range(1, int(eval(input())) + 1))
print((sum(gcd(gcd(a, b), c) for a in r for b in r for c in r)))

# Optimized solution
from math import gcd
r = list(range(1, int(eval(input())) + 1))
print((sum(gcd(gcd(a, b), c) for a in r for b in r for c in r)))
# Original solution
K = int(eval(input()))

from math import gcd
   
ans = 0
dic = {}
for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            time = len(set([i, j, k]))
            if time==3:
                t=6
            elif time==2:
                t=3
            else:
                t=1
            s = tuple(sorted([i, j, k]))
            if s in dic:
                ans += dic[s]
            else:
                a = gcd(gcd(i, j), k)
                ans += a*t
                dic[s] = a*t
                
print(ans)

# Optimized solution
from math import gcd

def solve():
  K = int(eval(input()))
  ans = 0
  for i in range(1, K+1):
      for j in range(1, K+1):
          a = gcd(i, j)
          for k in range(1, K+1):
            ans += gcd(a, k)
  return ans
                
print((solve()))
# Original solution
from math import gcd

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

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

# Optimized solution
from math import gcd

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

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

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())

def exit():
    import sys
    sys.exit(0)


def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))


d = dict()
d2 = dict()

def check(a, b, d2):
    t = tuple(sorted([a,b]))
    if t in d2:
        return d2[t]
    return False

k = load()
s = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1, k+1):
            r = check(i, j, d2)
            target = None
            if r:
                target = k
            else:
                r = check(j, k, d2)
                if r:
                    target = i
                else:
                    r = check(i, k, d2)
                    if r:
                        target = j
                    else:
                        # print(i,j,k)
                        d2[(i,j)] = gcd(i,j)
                        r = d2[(i,j)]
                        target = k
            r2 = check(r, target, d2)
            if r2:
                s += r2
            else:
                d2[(r, target)] = gcd(r, target)
                s += d2[(r, target)]

print(s)
                

# Optimized solution
from math import gcd
 
def main():
    k = int(eval(input()))
    ans = 0
 
    for a in range(1, k+1):
        for b in range(1, k+1):
            for c in range(1, k+1):
                ans += gcd(gcd(a, b), c)
 
    print(ans)
 
if __name__ == "__main__":
    main()
# Original solution
from itertools import combinations
import math
from functools import reduce

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

n = int(eval(input()))

a = []
for i in range(1, n+1):
    a += [i, i, i]

x = list(set(combinations(a, 3)))

total = 0
for i, j, k in x:
    if i == j and j == k and k == i:
        total += gcd_list([i, j, k])

    elif i != j and j != k and i != k:
        total += 6 * gcd_list([i, j, k])
    
    else:
        total += 3 * gcd_list([i, j, k])
        
print(total)

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

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

n = int(eval(input()))

total = 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 and j == k and i == k:
                x = 1
            elif i != j and j != k and i != k:
                x = 6
            else:
                x = 3
            
            total += x * gcd_list([i, j, k])
        
print(total)
# Original solution
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
# import math
import sys
import collections

from math import gcd
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

K = int(eval(input()))
""" answer 1
ans = 0
tmp = {}
for i in range(201):
    tmp[i] = 0

for i in range(1, K +1):
    for j in range(1, K +1):
        tmp[math.gcd(i, j)] += 1

for k in range(1, K +1):
    for key in tmp.keys():
        ans += math.gcd(key, k) * tmp[key]
print(ans)

"""

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

# Optimized solution
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
# import math
import sys
import collections

from math import gcd
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

K = int(eval(input()))
""" answer 1
ans = 0
tmp = {}
for i in range(201):
    tmp[i] = 0

for i in range(1, K +1):
    for j in range(1, K +1):
        tmp[math.gcd(i, j)] += 1

for k in range(1, K +1):
    for key in tmp.keys():
        ans += math.gcd(key, k) * tmp[key]
print(ans)

"""


"""answer 2　ぎりぎり
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)

"""

ans = 0

# (1,2,3)
for i in range(1, K +1):
    for j in range(i+ 1, K + 1):
        for k in range(j + 1, K + 1):
            ans += gcd(gcd(i, j), k) * 6

# (1,2,2)
for i in range(1, K + 1):
    for j in range(i+ 1, K+1):
        ans += gcd(i, j) * 3 * 2

# (1,1,1)
for i in range(1, K +1):
    ans += i
print(ans)
# Original solution
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug
from functools import lru_cache

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect

@lru_cache(maxsize=None)
def mutual_division_method(a, b):
    while not (a == 0 or b == 0):
        if a > b:
            a = a % b
        else:
            b = b % a
    if a == 0:
        return b
    else:
        return a

def mdm(a, b):
    if a < b:
        b, a = a, b
    return mutual_division_method(a, b)


def gcd(a, b, c):
    #print('a, b, c', a, b, c) # debug
    d = mdm(a, b)
    e = mdm(d, c)
    #print('e', e) # debug
    return e

if __name__ == '__main__':
    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):
                ans = gcd(a, b, c)
                s += ans
    #print('s') # debug
    print(s)

    #print('\33[32m' + 'end' + '\033[0m') # debug


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

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug
from functools import lru_cache

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect

def mutual_division_method(a, b):
    while not (a == 0 or b == 0):
        if a < b:
            b = b % a
        else:
            a = a % b
    if a == 0:
        return b
    else:
        return a



def gcd(a, b, c):
    #print('a, b, c', a, b, c) # debug
    d = mutual_division_method(a, b)
    e = mutual_division_method(d, c)
    #print('e', e) # debug
    return e

if __name__ == '__main__':
    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):
                l = a, b, c
                sorted(l)
                ans = gcd(*l)
                s += ans
    #print('s') # debug
    print(s)

    #print('\33[32m' + 'end' + '\033[0m') # debug
# Original solution

#from math import gcd
import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)

K = int(eval(input()))

def gcd(x,y):
    while y:
        x, y = y, x % y
    return x

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


# Optimized solution

from math import gcd
import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)

K = int(eval(input()))

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

from math import gcd
import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)

K = int(eval(input()))

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


# Optimized solution
from math import gcd
import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)

K = int(eval(input()))

ans = 0
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):
            ans += gcd(tmp, k)
print(ans)
# Original solution
import math
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(read())
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
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

k = int(read())
ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        n = math.gcd(a, b)
        for c in range(1, k + 1):
            ans += math.gcd(n, c)
print(ans)
# Original solution
gcd_memo = {}


def gcd(a, b):
    if b == 0:
        return a
    else:
        r = a % b
        gcd_memo[(a, b)] = gcd(b, r)
        return gcd_memo[(a, b)]


if __name__ == "__main__":
    K = int(eval(input()))
    ans = 0
    for a in range(1, K+1):
        for b in range(1, K+1):
            for c in range(1, K+1):
                tmp = gcd(gcd(a, b), c)
                ans += tmp
    print(ans)


# Optimized solution
gcd_memo = {}


def gcd(a, b):
    if b == 0:
        return a
    elif (a, b) in gcd_memo:
        return gcd_memo[(a, b)]
    else:
        r = a % b
        gcd_memo[(a, b)] = gcd(b, r)
        gcd_memo[(b, a)] = gcd_memo[(a, b)]
        return gcd_memo[(a, b)]


if __name__ == "__main__":
    K = int(eval(input()))
    ans = 0
    for a in range(1, K+1):
        for b in range(1, K+1):
            for c in range(1, K+1):
                tmp = gcd(gcd(a, b), c)
                ans += tmp
    print(ans)
# Original solution
import math

K = int(eval(input()))

sum = 0
cache = {}
for a in range(1, K+1) :
    for b in range(1 , K+1) :
        for c in range(1 , K+1) :
            bc = str(b) + "-" + str(c)
            if bc in cache :
                sum = sum + math.gcd(a, cache[bc])
            else :
                cache[bc] = math.gcd(b, c)
                sum = sum + math.gcd(a, cache[bc])

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) :
        tmp = math.gcd(a, b)
        for c in range(1 , K+1) :
            sum = sum + math.gcd(tmp, c)

print(sum)
# Original solution
import fractions
import math

K = int(eval(input()))
sum = 0
kl = list(range(1, K+1))
combdict = {}

for i in kl:
    for j in kl:
        for k in kl:
            sum += math.gcd(i, math.gcd(j, k))
print(sum)

# Optimized solution
import math

K = int(eval(input()))
sum = 0
kl = list(range(1, K+1))

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

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

print(ans)
# Original solution
import math

d = dict()
k = int(eval(input()))
sm = 0

def g(x, y, z):
    t = sorted([x,y,z])
    d.setdefault(str(t), 0)
    if d[str(t)] == 0:
        s = math.gcd(math.gcd(a, b), c)
        d[str(t)] = s
        return s
    else:
        return d[str(t)]

for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            sm += g(a,b,c)

print(sm)


# Optimized 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)
# Original solution

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


K = int(eval(input()))
total = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        tmp = gcd(a, b)
        for c in range(1, K+1):
            total += gcd(tmp, c)

print(total)


# Optimized solution
from math import gcd

K = int(eval(input()))
total = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        tmp = gcd(a, b)
        for c in range(1, K+1):
            total += gcd(tmp, c)

print(total)
# 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
def gcd(a,b):
    while b!=0:
        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
from math import gcd
def main():
    k = int(eval(input()))
    r = 0
    for ia in range(1, k + 1):
        for ib in range(1, k + 1):
            for ic in range(1, k + 1):
                t1 = gcd(ib, ic)
                r += gcd(t1,ia)
    print(r)

if __name__ == '__main__':
    main()

# Optimized solution
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import gcd
def main():
    k = int(eval(input()))
    r = 0
    for i1 in range(1, k + 1):
        for i2 in range(1, k + 1):
            for i3 in range(1, k + 1):
                t1 = gcd(i1, i2)
                r += gcd(t1, i3)
    print(r)

if __name__ == '__main__':
    main()
# Original solution
k = int(eval(input()))

ans = []

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

from itertools import product

for (x1, x2, x3) in product(list(range(1, k+1)), repeat=3):
    ans.append(gcd(gcd(x1, x2), x3))

print((sum(ans)))


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

ans = []

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

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

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


k = int(eval(input()))
koho = list(range(1,k+1))*3
ans = 0
for i in set(list(itertools.combinations(koho, 3))):
    ans += gcd(list(i))
      
print(ans)

# Optimized solution
k = int(eval(input()))
hoge = [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((hoge[k-1]))
# 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(1,k+1):
        if gcd(a,b) == 1:
            sum += 1 * k
            continue
        for c in range(1,k+1):
            sum += gcd(a,b,c)

print(sum)
# Original solution
import math

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

# Optimized solution
import math

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

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

print(ans)
# Original solution
k=int(eval(input()))
import math
x=0
c=0
d=0
for i in range(1,k+1):
  for j in range(i,k+1):
    for k in range(j,k+1):
      d=math.gcd(i,j)
      c=math.gcd(d,k)
      if i!=j and j!=k:
        x+=6*c
      elif i==j==k:
        x+=c
      else:
        x+=3*c
print(x)

# Optimized solution
k=int(eval(input()))
import math
x=0
c=0
d=0
for i in range(1,k+1):
  for j in range(i,k+1):
    for k in range(j,k+1):
      d=math.gcd(i,j)
      c=math.gcd(d,k)
      if i!=j and j!=k:
        x+=6*c
      elif (i!=j and j==k) or (k!=i and i==j):
        x+=3*c
      else:
        x+=c
print(x)