Problem:
 Score : 300 points    Problem Statement Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)} .  Here \gcd(a,b,c) denotes the greatest common divisor of a , b , and c .      Constraints  1 \leq K \leq 200  K is an integer.         Input Input is given from Standard Input in the following format:  K       Output Print the value of \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)} .        Sample Input 1 2      Sample Output 1 9  \gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)  +\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)  =1+1+1+1+1+1+1+2=9  Thus, the answer is 9 .       Sample Input 2 200      Sample Output 2 10813692

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

























def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007




def main():
	N = inputInt()

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

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

	while a > 0:
		a, b = b % a, a
	return b






class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        
        
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        
        self.prev = defaultdict(lambda: None)

        
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]

def int_sqrt2(n):
    def f(prev):
        while True:
            m = (prev + n / prev) / 2
            if m >= prev:
                return prev
            prev = m

    return f(int(math.sqrt(n) * (1 + 1e-10)))



def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y



def H(n, r, mod=10**9+7):
	
	
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        
        
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Solution (Python):
K = int(input())
import math
b_list=[]
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)
            b_list.append(b)
print(sum(b_list))

Solution (Python):

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


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

Solution (Python):
from math import gcd

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

Solution (Python):
from math import gcd
k = int(input())
double = [gcd(i, j) for i in range(1, k+1) for j in range(1, k+1)]
triple = [gcd(i, j) for i in range(1, k+1) for j in double]
print(sum(triple))

Solution (Python):
from math import gcd
from functools import reduce


k = int(input())

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

k += 1
ans = 0









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


print(ans)

Solution (Python):
import math
K = int(input())
res = sum([math.gcd(math.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(res)

Solution (Python):
def gcd(a, b):
    if a < b:
        return gcd(b, a)
    d = a % b
    if d == 0:
        return b
    return gcd(b, d)

def main():
    K = int(input())
    table = [[0]*K for i in range(K)]
    for i in range(K):
        for j in range(K):
            table[i][j] = gcd(i + 1, j + 1)
    ans = 0
    for i in range(K):
        for j in range(K):
            for k in range(K):
                ans += gcd(i + 1, table[j][k])
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from math import gcd
N = int(input())
sum = 0
for i in range(1, N+1):
    for j in range(1, N+1):
        tmp=gcd(i,j)
        for k in range(1, N+1):
            sum += gcd(tmp,k)
print(sum)

Solution (Python):
def gcd(x, y):
    if x == 0:
        return y
    if x == 1 or y == 1:
        return 1
    
    return gcd(y % x, x)


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

print(ans)

Solution (Python):
K = int(input())

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

gcd_table = [[0] * (K+1) for i in range(K+1)]
for i in range(1, K+1):
    for j in range(i, K+1):
        g = gcd(i, j)
        gcd_table[i][j] = gcd_table[j][i] = g


ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            g1 = gcd_table[a][b]
            g2 = gcd_table[g1][c]
            ans += g2

print(ans)

Solution (Python):
import math
from functools import reduce


k = int(input())

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

k += 1
ans = 0

for i in range(1,k):
    for j in range(i,k):
        
        if i == j:
            ans += gcd(i,j)
        else:
            ans += gcd(i,j)*6

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


print(ans)

Solution (Python):
from math import gcd
k = int(input())
res = 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):
            res += gcd(t,c)
print(res)

Solution (Python):










"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:
    return a
  return gcd_(a,a % b) 
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


"""def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def lcm(a,b):
  g = gcd(a,b)
  return (a * b) // g"""


"""import bisect 
print(A,bisect.bisect_left(A,4))
print(C,n - bisect.bisect_right(C,4))
print(sum(bisect.bisect_left(A,b) * (n-bisect.bisect_right(C,b)) for b in B))"""


"""import math
pi_ = math.pi"""


"""def Erato(n):
    prime = []
    is_prime = [True] * (n+1)
    p = 0
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2,n+1):
      if is_prime[i] == True:
        prime.append(i)
        p += 1
        for j in range(2 * i,n+1,i):
          is_prime[j] = False
    return p"""

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  import math
  k = int(input())
  ans = 0
  BC = []
  for b in range(1,k+1):
    for c in range(1,k+1):
      BC.append(math.gcd(b,c))
  for a in range(1,k+1):
    for bc in BC:
      ans += math.gcd(a,bc)
  print(ans)
if __name__ == '__main__':
  main()

Solution (Python):

from math import gcd
k = int(input())
a = 0
b = 0
ans = 0
memo =[[[0 for _1 in range(k+1)] for _ in range(k + 1)] for _2 in range(k + 1)]
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)

print(ans)

Solution (Python):

from math import gcd

def main():
    k = int(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()

Solution (Python):
from math import gcd 
N = int(input())
i = 0
 
for a in range(1, N+1):
    for b in range(1, N+1):
        for c in range(1, N+1):
            i += gcd(gcd(a, b), c)
            
print(i)

Solution (Python):
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

from math import gcd

k = int(readline())
cnt = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcd_ans = gcd(i, j)
        for l in range(1, k + 1):
            cnt += gcd(l, gcd_ans)
print(cnt)

Solution (Python):
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(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)

Solution (Python):
K = int(input())
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
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,j,k)

print(sum)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter

from functools import reduce
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]




n=ii()
def gcd_list(numbers):
    return reduce(gcd, numbers)
ans=0
for i in range(1,n+1):
    for j in range(i,n+1):
        for k in range(j,n+1):
            temp=0
            if len(list(set([i,j,k])))==1:
                temp=1
            elif len(list(set([i,j,k])))==2:
                temp=3
            else:
                temp=6
            ans+=gcd(gcd(i,j),k)*temp
print(ans)

Solution (Python):
import sys
from math import gcd

def solve(K: int):

    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)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  
    solve(K)

if __name__ == '__main__':
    main()

Solution (Python):
import math
K = int(input())
S = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    g = math.gcd(a, b)
    for c in range(1, K+1):
      S += math.gcd(g, c)
print(S)

Solution (Python):
from math import gcd
k = int(input()) + 1
ans = 0
for i in range(1,k):
  for j in range(1,k):
    for l in range(1,k):
      ans += gcd(gcd(i, j),l)
print(ans)

Solution (Python):
K = int(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)

Solution (Python):
import math as m

K = int(input())

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

print(res)

Solution (Python):
k=int(input())

from math import gcd

gcd_sum=[0]*201
ans=0

for i in range(1,k+1):
    for j in range(1,k+1):
        gcd_sum[i]+=gcd(i,j)

for a in range(1,k+1):
    for b in range(1,k+1):
        g=gcd(a,b)
        ans += gcd_sum[g]

print(ans)

Solution (Python):
from math import gcd
K = int(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)

Solution (Python):

K = int(input())
 

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
ans = 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):
            ans += gcd(gcd_ij, k)

print(ans)

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

Solution (Python):
from math import gcd

K = int(input())

res = [gcd(a, gcd(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(res))

Solution (Python):
from math import*;r=range(1,int(input())+1);print(sum(gcd(a,gcd(b,c))for a in r for b in r for c in r))

Solution (Python):
from math import gcd
K = int(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)

Solution (Python):
import math
import sys
from io import StringIO
import unittest
from functools import reduce

def resolve():
    k = int(input())

    abc = [0, 0, 0]
    ans = 0

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

            abc[j] = i

            if 0 in abc:
                continue

            work = reduce(math.gcd, abc)
            if not abc[0] == abc[1] == abc[2]:
                work = work * 3
            ans += work
            print(str(abc) + "| " +str(work))

    print(ans)



def not_resolve2():
    k = int(input())

    ans = 0

    for a in range(1, k + 1):
        
        for b in range(a, k + 1):
            for c in range(b, k + 1):
                work = reduce(math.gcd, [a, b, c])
                if a == b == c:
                    print("これは×3しない")
                    print(str(a) + "|" + str(b) + "|" + str(c) + "=" + str(work))
                    
                    pass
                else:
                    print("これは×3する")
                    print(str(a) + "|" + str(b) + "|" + str(c) + "=" + str(work * 3))
                    work = work * 3
                ans += work

    print(ans)



def not_resolve():
    k = int(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 += reduce(math.gcd, [a, b, c])

    print(ans)



class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2"""
        output = """9"""
        self.assertIO(input, output)

    def test_入力例(self):
        input = """3"""
        output = """30"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """200"""
        output = """10813692"""
        self.assertIO(input, output)


if __name__ == "__main__":
    
    not_resolve()

Solution (Python):
import math as f

K = int(input())
total = 0

for i in range(1, K + 1):
    for j in range(1, K + 1):
        ij = f.gcd(i, j)
        if ij == 1:
            total += K
            continue
        for k in range(1, K + 1):
            total += f.gcd(ij, k)

print(total)

Solution (Python):
from math import gcd

K = int(input())

ans = 0

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

print(ans)

Solution (Python):
from math import gcd
k = int(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)

Solution (Python):

import math



def main():
    k = int(input())
    total = 0

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


if __name__ == '__main__':
    main()

Solution (Python):

K =int(input())


from functools import reduce
import math 
def lcm_base(x, y):
    return  math.gcd(x, y) 
def lcm_list(numbers):
    return reduce(lcm_base, numbers)
def lcm_fukusu(*numbers):
    return reduce(lcm_base, numbers)


saisyou_koyakusu =[]

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:
                saisyou_koyakusu.append(lcm_fukusu(i,j,k))
            elif i==j or j==k:
                saisyou_koyakusu.append( (lcm_fukusu(i,j,k))*3 )
            else:
                saisyou_koyakusu.append( (lcm_fukusu(i,j,k)) *6)

            
print(sum(saisyou_koyakusu))

Solution (Python):
def main():
    import math
    import sys

    input = sys.stdin.readline

    n = int(input())
    c_1 = 0

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

    print(c_1)

if __name__ ==  "__main__":
    main()

Solution (Python):
import math

K = int(input())

res = [math.gcd(a, math.gcd(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(res))

Solution (Python):
from math import gcd

def solve():
  K = int(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())

Solution (Python):


import numpy as np

K = int(input())

x = np.arange(1, K + 1)
nums = np.gcd.outer(np.gcd.outer(x, x), x)
print(nums.sum())

Solution (Python):
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
K = int(input()) 
a=0
for i in range(1,K+1):
  for j in range(1,K+1):
    for l in range(1,K+1):
      a=a+gcd(i,j,l)
print(a)

Solution (Python):
k = int(input())
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

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)

Solution (Python):
K=int(input())
import math

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

Solution (Python):

from math import gcd
K = int(input())
K += 1
ans = 0
for i in range(1, K):
    for j in  range(1, K):
        for k in range(1, K):
            ans += gcd(gcd(i, j), k)
print(ans)

Solution (Python):
from math import*;from itertools import*;r=range(1,int(input())+1);print(sum(gcd(a,gcd(b,c))for a,b,c in product(r,r,r)))

Solution (Python):
from math import gcd 
N = int(input())
i = 0
 
for a in range(1, N+1):
    for b in range(1, N+1):
        for c in range(1, N+1):
            i += gcd(gcd(a, b), c)
            
print(i)

Solution (Python):
import math

k = int(input())

tb = [
    [math.gcd(a, b) for a in range(0, 201)]
    for b in range(0, 201)
]

x = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        t = tb[a][b]
        for c in range(1, k + 1):
            x += tb[t][c]
print(x)

Solution (Python):










from math import gcd



def main():
    k = int(input())
    total = 0

    for a in range(1,k+1):
        for b in range(1,k+1):
            for c in range(1,k+1):
              temp = gcd(a,b)
              total += gcd(temp,c)
    print(total)


if __name__ == '__main__':
    main()

Solution (Python):
import math
k = int(input())
s = 0
for i in range(k):
    a = i+1
    for j in range(k):
        b = j+1
        for l in range(k):
            c = l+1
            s += math.gcd(math.gcd(a,b),c)

print(s)

Solution (Python):
from math import gcd

a = int(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()))

Solution (Python):
import math
from functools import reduce

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


k = int(input())
A=list()

for i in range(1,k+1):
  for j in range(1,k+1):
    for k in range(1,k+1):
        a=(gcd(i,j,k))
        A.append(a)
print(sum(A))

Solution (Python):
from math import gcd
 
k=int(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)

Solution (Python):

import math
K = int(input())
sum_gcd = 0
for a in range(1,K+1):
    for b in range(1,a+1):
        for c in range(1,b+1):
            if a == b and b == c :
                sum_gcd += math.gcd(math.gcd(a,b),c)
            elif a == b or b == c or c == a:
                sum_gcd += 3 * math.gcd(math.gcd(a,b),c)
            else:
                sum_gcd += 6 * math.gcd(math.gcd(a,b),c)
print(sum_gcd)

Solution (Python):
from math import gcd
k = int(input())+1
ans = 0
for i in range(1,k):
    for j in range(1,k):
        for l in range(1,k):
            ans+=gcd(gcd(i,j),l)
print(ans)

Solution (Python):
import numpy as np

def resolve():
    N = int(input())
    A = np.arange(1, N+1)
    ans = np.gcd.outer(np.gcd.outer(A, A),A)
    return print((ans.sum()))

if __name__ == "__main__":
    resolve()

Solution (Python):
from math import gcd
ans = 0
k = int(input())
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)

Solution (Python):
from math import gcd
def main(): 
    k = int(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)
if __name__ == "__main__":
    main()

Solution (Python):
from math import gcd 

num = int(input()) + 1

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

Solution (Python):
from math import gcd
c = 0
r = range(1, int(input())+1)
for i in r:
    for j in r:
        for k in r:
            c += gcd(i, gcd(j, k))
print(c)

Solution (Python):
import math as np
K=int(input())
s3=0
s2=0
s1=0
s0=0
for a in range(1,K-1):
    for b in range(a+1,K):
        d=np.gcd(a,b)
        for c in range(b+1,K+1):
            s0+=np.gcd(c,d)
for a in range(1,K):
    for c in range(a+1,K+1):
        s1+=np.gcd(a,c)
for a in range(1,K):
    for b in range(a+1,K+1):
        s3+=np.gcd(a,b)
for k in range(K+1):
    s2+=k
print(s0*6+s1*3+s3*3+s2)

Solution (Python):
n=int(input())
import math
a=[0]*3
sum=0
for i in range(n):
  for j in range(n):
    for k in range(n):
      a[0]=i+1
      a[1]=j+1
      a[2]=k+1
      ans=a[2]
      for l in range(2):
        ans = math.gcd(ans, a[l])
      sum+=ans
print(int(sum))

Solution (Python):
import math

K = int(input())
G = [[0] *(K+1) for i in range(K+1)]

for a in range(1,K+1):
  t = 0
  for b in range(1,K+1):
    w = math.gcd(a,b)
    G[a][b] = w
    t += w
  G[a][0] = t

t = 0
for a in range(1,K+1):
  for b in range(1,K+1):
    w = G[a][b]
    t += G[w][0]

print(t)

Solution (Python):
from math import gcd
k = int(input())
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for k in range(1, k + 1):
            ans += gcd(gcd(i, j), k)
print(ans)

Solution (Python):
from math import gcd
ans = 0
K = int(input())
 
for i in range(1, K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      ans = ans + gcd(gcd(i,j), k)
      
print(ans)

Solution (Python):
from math import gcd
k = int(input())
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for k in range(1, k + 1):
            ans += gcd(gcd(i, j), k)
print(ans)

Solution (Python):
from math import gcd
n=int(input())
sum1=0
for i in range(1,n+1):
	for j in range(1,n+1):
		gcd1=gcd(i,j)
		for k in range(1,n+1):
			gcd2=gcd(gcd1,k)
			sum1+=gcd2
print(sum1)

Solution (Python):
from math import gcd
ans = 0
K = int(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)

Solution (Python):
from math import gcd
k = int(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)

Solution (Python):
import math

def resolve():
    N = int(input())
    ans = 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):
                ans += math.gcd(g,k)

    return print(ans)

if __name__ == "__main__":
    resolve()

Solution (Python):
import math
k = int(input())
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcd1 = math.gcd(i, j)
        for l in range(1, k + 1):
            gcd2 = math.gcd(gcd1, l)
            ans += gcd2
print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import gcd, ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
c = 0
K = INT()
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):
            b = gcd(a, k)
            ans += b
print(ans)

Solution (Python):
from math import gcd

k = int(input())
ans = 0

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

print(ans)

Solution (Python):
k=int(input())
from math import gcd
a=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1,k+1):
      a+=gcd(i,gcd(j,l))
print(a)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import gcd, ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
c = 0
K = INT()
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):
            b = gcd(a, k)
            ans += b
print(ans)

Solution (Python):
from math import gcd
K = int(input())
res = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            res += gcd(gcd(i, j), k)
print(res)

Solution (Python):
from math import gcd 

K=int(input())
S=0

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

print(S)

Solution (Python):
import math
K = int(input())
sumval = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            f = math.gcd(a,b)
            g = math.gcd(f,c)
            sumval += g
print(sumval)

Solution (Python):
from math import gcd
n = int(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(gcd(i, j), k)
print(sum)

Solution (Python):
K = int(input())  
import math
from functools import reduce

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

A = []
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 and k == i:
                
                A.append(gcd_list([i, j, k]))
            elif i != j and j != k and k != i:
                A.append(gcd_list([i, j, k])*6)
            else:
                
                A.append(gcd_list([i, j, k])*3)           

print(sum(A))

Solution (Python):
import math
from functools import reduce

gcd = lambda *numbers: reduce(math.gcd, numbers)

K = int(input())

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

print(answer)