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):

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


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


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    K = int(input())

    ans = 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):
                ans += gcd(x, c)
    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()

Solution (Python):
import math
from functools import reduce

k=int(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 l in range(1,k+1):
      ans+=gcd(i,j,l)

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

print(ans)

Solution (Python):
import math

K = int(input())
sum_num = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        tmp = math.gcd(i, j)
        for k in range(1, K + 1):
            sum_num += math.gcd(tmp, k)
print(sum_num)

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

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

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

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

print(ans)

Solution (Python):
import math
from functools import reduce

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

K = int(input())
ans = 0
for i in range(1,K+1) :
    ans += i
for i in range(1,K) :
    for j in range(i+1,K+1) :
        ans += math.gcd(i,j) * 6
if K >= 3 :
    for i in range(1,K-1) :
        for j in range(i+1,K) :
            for k in range(j+1,K+1) :
                ans += gcd(i,j,k) * 6
print(ans)

Solution (Python):
K = int(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(gcd(i, j),k)

print(sum)

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

Solution (Python):
import math


K = int(input())
result = 0

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

print(result)

Solution (Python):
import math
K = int(input())
total = 0
for x in range(1, K+1):
    for y in range(1, K+1):
        for z in range(1, K+1):
            total = total+math.gcd(x, math.gcd(y, z))
print(total)

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(gcd(a, b), c)
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(gcd(a, b), c)
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):
    ij = gcd(i, j)
    for t in range(1, k + 1):
      ans += gcd(ij, t)

print(ans)

Solution (Python):
import math

k = int(input())
ans = 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):
            ans += math.gcd(tmp, c)

print(ans)

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

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

Solution (Python):
import math
k = int(input());
    
sum = 0;
sum += (k*k*k-(k-1)*(k-1)*(k-1))

for p in range(2,k+1):
    for q in range(2,k+1):
        g = math.gcd(p,q);
        if g == 1:
            sum += k-1
        else:
            for r in range(2,k+1):
                sum += math.gcd(g,r);
            
print(sum);

Solution (Python):
import math

import itertools


def gcd(a, b, c):
    ans = math.gcd(a, b)
    ans = math.gcd(ans, c)

    return ans




k = int(input())

elem = [i+1 for i in range(k)]

combs = itertools.combinations_with_replacement(elem, 3)

tmp = [1, 2, 3]

s = 0
for comb in combs:
    s += sum(tmp[:len(set(comb))]) * gcd(comb[0], comb[1], comb[2])





print(s)

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

ans = 0

import math

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

print(ans)

Solution (Python):
from math import gcd
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):
import itertools
import functools
import math

def OK():
    N = int(input())

    sum = 0
    cnt = 0
    for i in range(1,N+1):
        for j in range(1,N+1):
            chk = math.gcd(i,j)
            for k in range(1,N+1):
                sum += math.gcd(chk,k)

    print(sum)

OK()

Solution (Python):
import math
K = int(input())
total = 0
for x in range(1, K+1):
    for y in range(1, K+1):
        a=math.gcd(x, y)
        for z in range(1, K+1):
            total = total+math.gcd(z, a)
print(total)

Solution (Python):
import math
n = int(input())
s = 0
for a in range(n):
    for b in range(n):
        d = math.gcd(a + 1, b + 1)
        for c in range(n):
            s += math.gcd(c + 1, d)
print(s)

Solution (Python):
import math

K = int(input())
ans = 0

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

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

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

Solution (Python):
import math

k = int(input())
ans = 0

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

print(ans)

Solution (Python):
from math import gcd

k = int(input())
ans = 0

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

print(ans)

Solution (Python):
from functools import reduce
import math

k = int(input())

s = 0

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

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

print(s)

Solution (Python):
import math

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

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

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

print(ans)

Solution (Python):
import math

k = int(input())
ans = 0
for h in range(1,k+1):
    for i in range(1,k+1):
        for j in range(1,k+1):
            t = math.gcd(h, i)
            ans += math.gcd(t, j)

print(ans)

Solution (Python):

import sys
import numpy as np
from math import gcd


K = int(sys.stdin.readline())
sum = 0

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


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

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

print(int(sum))

Solution (Python):
import math
cnt=0
n=int(input())
for i in range(1,n+1):
    for j in range(1,n+1):
        wk=math.gcd(i,j)
        for k in range(1,n+1):
            cnt+=math.gcd(wk,k)
print(cnt)

Solution (Python):
import math

k = int(input())
k_range = range(1, k + 1)

sum_gcd = 0
for l in k_range:
    temp = 0
    for m in k_range:
        temp = math.gcd(l, m)
        for n in k_range:
            sum_gcd += math.gcd(n, temp)

print(sum_gcd)

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

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

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):
import math
from functools import reduce

K=int(input())


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)

Solution (Python):
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

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

print(ans)

Solution (Python):
import math

K = int(input())
ans = 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):
      ans += math.gcd(ab,c)

print(ans)

Solution (Python):
from itertools import combinations_with_replacement


def euclidean(num_list: list):
    a, b = sorted(num_list)
    while b % a != 0:
        redi = b % a
        b = a
        a = redi
    return a


K = int(input())
k_range = list(range(1, K+1))

result = 0
for comb in combinations_with_replacement(k_range, 3):
    min_abc = min(comb)
    gcd = euclidean(comb[0:2])
    gcd = euclidean([gcd, comb[2]])
    if comb[0]==comb[1] and comb[1]==comb[2]:
        coef = 1
    elif (comb[0]!=comb[1] and comb[1]!=comb[2]) and comb[2]!=comb[0]:
        coef = 6
    else:
        coef = 3
    result += gcd * coef
print(result)

Solution (Python):
from itertools import combinations_with_replacement


def euclidean(num_list: list):
    a, b = sorted(num_list)
    while b % a != 0:
        redi = b % a
        b = a
        a = redi
    return a


K = int(input())
k_range = list(range(1, K+1))

result = 0
for comb in combinations_with_replacement(k_range, 3):
    min_abc = min(comb)
    gcd = euclidean(comb[0:2])
    gcd = euclidean([gcd, comb[2]])
    if comb[0]==comb[1] and comb[1]==comb[2]:
        coef = 1
    elif (comb[0]!=comb[1] and comb[1]!=comb[2]) and comb[2]!=comb[0]:
        coef = 6
    else:
        coef = 3
    result += gcd * coef
print(result)

Solution (Python):
from itertools import combinations_with_replacement

K = int(input())
k_range = list(range(1, K+1))

result = 0
for comb in combinations_with_replacement(k_range, 3):
    min_abc = min(comb)
    for i in range(min_abc, 0, -1):
        if (comb[0]%i == 0 and comb[1]%i == 0) and comb[2]%i == 0:
            if comb[0]==comb[1] and comb[1]==comb[2]:
                coef = 1
            elif (comb[0]!=comb[1] and comb[1]!=comb[2]) and comb[2]!=comb[0]:
                coef = 6
            else:
                coef = 3
            result += i * coef
            break
print(result)

Solution (Python):
import sys
read = sys.stdin.buffer.read






def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))

import math


def main():
	
	k=II()
	
	ans=0
	
	li=[0]*(k+1)
	
	for a in range(1,k+1):
		for b in range(1,k+1):
			li[math.gcd(a,b)]+=1
	
	for i in range(1,k+1):
		for c in range(1,k+1):
			if li[i]!=0:
				ans+=li[i]*math.gcd(i,c)
				
	
	print(ans)





	
if __name__ == "__main__":
	main()

Solution (Python):
import sys
read = sys.stdin.buffer.read






def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))

import math


def main():
	
	k=II()
	
	ans=0
	
	li=[0]*(k+1)
	
	for a in range(1,k+1):
		for b in range(1,k+1):
			li[math.gcd(a,b)]+=1
	
	for i in range(1,k+1):
		for c in range(1,k+1):
			ans+=li[i]*math.gcd(i,c)
				
	
	print(ans)





	
if __name__ == "__main__":
	main()

Solution (Python):
import sys
read = sys.stdin.buffer.read






def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))

import math


def main():
	
	k=II()
	
	ans=0
	
	li=[[0]*(k+1) for i in range(k+1)]
	
	for a in range(1,k+1):
		for b in range(1,k+1):
			for c in range(1,k+1):
				d=math.gcd(a,b)
				ans+=math.gcd(d,c)
				
	
	print(ans)





	
if __name__ == "__main__":
	main()

Solution (Python):
import sys
read = sys.stdin.buffer.read






def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))

import math


def main():
	
	k=II()
	
	ans=0
	
	li=[[0]*(k+1) for i in range(k+1)]
	
	for a in range(1,k+1):
		for b in range(1,k+1):
			for c in range(1,k+1):
				d=math.gcd(a,b)
				ans+=math.gcd(d,c)
				
	
	print(ans)





	
if __name__ == "__main__":
	main()

Solution (Python):
import sys
read = sys.stdin.buffer.read






def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))

import math


def main():
	
	k=II()
	
	ans=0
	
	li=[[0]*(k+1) for i in range(k+1)]
	
	for a in range(1,k+1):
		for b in range(1,k+1):
			li[a][b]=math.gcd(a,b)
	
	
	for a in range(1,k+1):
		for b in range(1,k+1):
			for c in range(1,k+1):
				ans+=math.gcd(li[a][b],c)
				
	
	print(ans)





	
if __name__ == "__main__":
	main()

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


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


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)

Solution (Python):

from math import gcd


k = int(input())
gg = [0] * k
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        temp = gcd(i, j)
        for l in range(1, k + 1):
            ans += gcd(temp, l)

print(ans)

Solution (Python):
import math

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

Solution (Python):
import math
from functools import reduce

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

K = int(input())

sum = 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:
                sum += gcd(a,b,c)
            elif a == b or b == c:
                sum += gcd(a,b,c) * 3
            else:
                sum += gcd(a,b,c) * 6
print(sum)

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

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

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

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

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

total = 0
for i in range(1,K+1,1):
  for j in range(1,K+1,1):
    tmp1 = i
    tmp2 = j
    while tmp1 % tmp2 != 0:
      tmp = tmp1 % tmp2
      tmp1 = tmp2
      tmp2 = tmp
    for k in range(1,K+1,1):
      tmp1 = k
      tmp3 = tmp2
      while tmp1 % tmp3 != 0:
        tmp = tmp1 % tmp3
        tmp1 = tmp3
        tmp3 = tmp
      total += tmp3
print(total)

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

result=0
for i in range(1,k+1):
    for j in range(1,k+1):
        first=math.gcd(i,j)
        for g in range(1,k+1):
            result=result+math.gcd(first,g)
print(result)

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) :
        p = gcd(i,j)
        for l in range (1,k+1) :
            ans += gcd(p,l)

print(ans)

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

Solution (Python):
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

K = int(input())

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

print(ans)

Solution (Python):
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

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)

Solution (Python):
import math

k = int(input())

ans = 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):
            ans += math.gcd(x, c)
print(ans)

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

sm=0
for i in range(1,k+1):
    for l in range(1,k+1):
        gcdab=math.gcd(i,l)
        for m in range(1,k+1):
            sm+=math.gcd(gcdab,m)

print(sm)

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

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

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

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

Solution (Python):

import math
from functools import reduce

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

K = int(input())
combinations = []
combinations.extend([[i+1]*3 for i in range(K)])
for i in range(K):
    combinations.extend([[i+1,i+1,j+1] for j in range(K) if j>i])
    for j in range(K):
        combinations.extend([[i+1,j+1,k+1] for k in range(K) if (j>i and k>j)])
result=0
for combination in combinations:
    a, b, c = combination
    if(a==b and b==c):
        result += a
    elif((a==b and b!=c) or (b==c and c!=a) or (c==a and a!=b)):
        result += gcd(a,b,c)*6
    else:
        result += gcd(a,b,c)*6
    
print(result)

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

Solution (Python):
import math

K = int(input())
ans = 0

A = {}
for a in range(1, K+1):
    A[a] = 0

for a in range(1, K+1):
    for b in range(1, K+1):
        num = math.gcd(a, b)
        A[num] += 1

for c in range(1, K+1):
    for k in A.keys():
        num = math.gcd(c, k) * A[k]
        ans += num

print(ans)

Solution (Python):
from math import gcd

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

Solution (Python):
k = int(input())
def gcd(a, b):
    if b == 0:
        return a
    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):
from math import gcd

ans = 0
k = int(input())
for i in range(1, k + 1):
  for j in range(1, k + 1):
    a = gcd(i, j)
    for l in range(1, k + 1):
      ans += gcd(a, l)
print(ans)

Solution (Python):
from math import gcd

K = int(input())
sum = 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):
            sum += gcd(A,k)
    
print(sum)

Solution (Python):
import math
K = int(input())
sum = 0
for i in range(1, K+1):
  for j in range(i, K+1):
    
    if (i == j):
      for k in range(i, K+1):
        
        if ((i == j) and (i == k)):
          sum += math.gcd(i, math.gcd(j, k))
        else:
          sum += (3*math.gcd(i, math.gcd(j, k)))
    
    else:
      for k in range(i+1, K+1):
        
        sum += (3*math.gcd(i, math.gcd(j, k)))
      
print(sum)

Solution (Python):
import math, itertools
from functools import reduce
def gcd_list(numbers):
    return(reduce(math.gcd,numbers))
k=int(input())
ans=0
for numbers in itertools.combinations_with_replacement(range(1,k+1),3):
    a,b,c=numbers
    if a==b==c:
        ans+=gcd_list(numbers)
    elif a!=b and a!=c and b!=c:
        ans+=6*gcd_list(numbers)
    else:
        ans+=3*gcd_list(numbers)
print(ans)

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

Solution (Python):
import math
from functools import reduce

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

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

Solution (Python):
import functools
import math

K = int(input())

def gcd_2(*vals):
    return functools.reduce(math.gcd, vals)

ans=0
for x in range(1,K+1):
    for y in range(1,K+1):
        for z in range(1,K+1):
            ans += gcd_2(x,y,z)

print(ans)

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

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) :
        X = gcd(a, b)
        for c in range(1,K+1) :
           Y = gcd(X, c)
           ans += Y

print(ans)

Solution (Python):
def gcd(p,q):
    while q != 0:
        r = p % q
        p = q
        q = r
    return p
k = int(input())
a = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            a += gcd(gcd(i,j),k)
print(a)

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

import math
from functools import reduce

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

ans = 0

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

print(ans)

Solution (Python):
import math


def main():
    K = int(input())
    s = 0
    for i in range(K):
        for j in range(K):
            tmp = math.gcd(i+1, j+1)
            for k in range(K):
                s += math.gcd(tmp, k+1)

    print(s)


if __name__=="__main__":
    main()

Solution (Python):
import math


def main():
    K = int(input())
    s = 0
    for i in range(1, K+1):
        for j in range(1, K + 1):
            tmp = math.gcd(i, j)
            for k in range(1, K + 1):
                s += math.gcd(tmp, k)

    print(s)


if __name__=="__main__":
    main()

Solution (Python):
import math
from functools import reduce


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


def main():
    K = int(input())
    s = sum([gcd(i+1, j+1, k+1) for i in range(K) for j in range(K) for k in range(K)])

    print(s)


if __name__=="__main__":
    main()

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):
from math import gcd

K = int(input()) + 1
num = 0

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

print(num)

Solution (Python):
import math
from functools import reduce

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

print(ans)

Solution (Python):
import math
from functools import reduce

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 += reduce(math.gcd, [i, j, l])

print(ans)

Solution (Python):
import math

k = int(input())
ans = 0

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

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

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


K = int(input())
ans = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        g1 = gcd(a, b)
        if g1 == 1:
            ans += K
        else:
            for c in range(1, K+1):
                ans += gcd(g1, c)
print(ans)

Solution (Python):
K   = int(input())
Sum = 0
def mygcd(x,y):
    a = min(x,y)  
    b = max(x,y)  
    r = 2  
    while r != 0:
        r = b % a
        b = a
        a = r
    return b

for A in range(1,K+1):
    for B in range(1,K+1):
        AB = mygcd(A,B)
        if AB==1:
            Sum = Sum+K
        else:
            for C in range(1,K+1):
                Sum = Sum+mygcd(AB,C)
print(Sum)

Solution (Python):
import math

k = int(input())
s = 0

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


for a in range(1, k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            d = gcd3(a, b, c)
            if a == b and b == c:
                s += d
            elif a == b or b == c:
                s += d * 3
            else:
                s += d * 6

print(s)

Solution (Python):
import math
K   = int(input())
Sum = 0
for A in range(1,K+1):
    for B in range(1,K+1):
        AB = math.gcd(A,B)
        if AB==1:
            Sum = Sum+K
        else:
            for C in range(1,K+1):
                Sum = Sum+math.gcd(AB,C)
print(Sum)

Solution (Python):
import math
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 = Sum+math.gcd(math.gcd(A,B),C)
print(Sum)

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

Solution (Python):
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

if __name__ == "__main__":
    N = int(input())
    ans = 0

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

    print(ans)

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

Solution (Python):
from math import gcd
k = int(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 += gcd(gcd(x, y), z)
print(ans)

Solution (Python):
def resolve():
    import math
    K = int(input())
    ans = []
    for i in range(1, K+1):
        for j in range(1, K+1):
            for p in range(1, K+1):
                q = math.gcd(i, j)
                ans.append(math.gcd(q, p))
    print(sum(ans))
resolve()

Solution (Python):
import math
import numpy as np
k = int(input())

Map = [[0 for j in range(k)] for i in range(k)]
for i  in range(1,k+1):
    for j in range(1,k+1):
        tmp = math.gcd(i,j)
        Map[i-1][j-1] = tmp
        Map[j-1][i-1] = tmp

ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        tmp_ans = Map[i-1][j-1]
        for x in range(1,k+1):
            ans += Map[tmp_ans-1][x-1]
            
            
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):
        tmp = math.gcd(i,j)
        for x in range(1,k+1):
            ans +=math.gcd(tmp,x) 

            
print(ans)