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 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):
k = int(input())
sum = 0


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


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

Solution (Python):

"""
Created on Wed May  6 01:11:37 2020

@author: shinba
"""
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):
    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())
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)

Solution (Python):
k = int(input())+1
def gcd(a,b):
  if a < b:
    a, b = b, a
  while b!=0:
    a, b = b ,a%b
  return a
res = 0
for a in range(1,k):
  for b in range(1,k):
    for c in range(1,k):
      res += gcd(a,gcd(b,c))

print(res)

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

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

import math
total=0
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)
            e=math.gcd(d,c)
            total=total+e
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):
    ab = gcd(a,b)
    for c in range(1,k+1):
      ans += gcd(ab,c)
print(ans)

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

ans = 0
from math import gcd


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

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

k = int(input())
ab = 0
abc = 0
ans = 0

for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ab = calc(b,a)
            abc = calc(c,ab)
            ans += abc

print(str(ans))

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


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


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

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

ll = []
for i in range(1, k + 1):
    l = []
    for j in range(1, i + 1):
        if i % j == 0:
            l.append(j)
            l.append(i // j)
        if (i // j) < j:
            break
    ll.append(set(l))


sum_k = 0

for i in range(k):
    i_s = ll[i]
    for j in range(k):
        j_s = ll[j]
        m = max(ll[i] & ll[j])
        if m == 1:
            sum_k += k
            continue
        for l in range(k):
            sum_k += max(ll[i] & ll[j] & ll[l])

print(sum_k)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    k = I()
    r = 0
    for a,b,c in itertools.product(range(1,k+1), repeat=3):
        r += math.gcd(math.gcd(a,b), c)

    return r


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

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

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 sys
sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

from math import gcd

def solve():
    k = II() + 1
    ans = 0
    for a in range(1, k):
        for b in range(1, k):
            g = gcd(a, b)
            for c in range(1, k):
                ans += gcd(g, c)
    print(ans)


if __name__ == '__main__':
    solve()

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

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

Solution (Python):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
K=int(input())
ans=[]
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans.append(gcd(i,j,k))
print(sum(ans))

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

Solution (Python):
import math
s=0
k=int(input())
for i in range(k,0,-1):
  for j in range(k,0,-1):
    d=math.gcd(i,j)
    for h in range(k,0,-1):
      s+=math.gcd(d,h)
print(s)

Solution (Python):
import math

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

Solution (Python):
import numpy as np
k = int(input())
a = 0
for i in range(1,k+1):
  for j in range(1,k+1):
    d = np.math.gcd(i,j)
    for l in range(1,k+1):
      e = np.math.gcd(d,l)
      a += e
print (a)

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

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

ans = 0
for i in range(1, k+1):
    count = count_lst[i-1]

    for j in range(1,k+1):
        g = math.gcd(i,j)
        ans += count * g

print(ans)

Solution (Python):
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=q
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)

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

sum = 0

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

print(sum)

Solution (Python):
import math
output = 0
K = int(input())
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):
            output += math.gcd(r,k)
            
print(output)

Solution (Python):
"""
gcd(a,b,c) = gcd(a, gcd(b,c))
"""

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
K = int(readline())

from math import gcd

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)

Solution (Python):
import math
import itertools

k = int(input().strip())
gcdsum = 0

for a, b, c in itertools.combinations_with_replacement(range(1, k + 1), 3):
    if a == b and b == c:
        gcdsum += math.gcd(math.gcd(a, b), c) * 1
    elif a != b and b == c:
        gcdsum += math.gcd(math.gcd(a, b), c) * 3
    elif a == b and b != c:
        gcdsum += math.gcd(math.gcd(a, b), c) * 3
    elif a != b and b != c:
        gcdsum += math.gcd(math.gcd(a, b), c) * 6
print(gcdsum)

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

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

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

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, gcd
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter

import sys
def I(): return int(input())  
def Is(): return map(int, input().split())  
def LI(): return list(map(int, input().split()))  
def TI(): return tuple(map(int, input().split()))  
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  
def LS(): return list(input())  
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

K = I()

ans = 0
for a, b, c in combinations_with_replacement(range(1, K+1), 3):
    
    score = gcd(a,gcd(b,c))
    
    l = len({a, b, c})
    
    if l == 3:
        ans += score*6
    elif l == 2:
        ans += score*3
    else:
        ans += score

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

print(ans)

Solution (Python):
K = int(input())
import math
gcdsum = 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):
            gcdsum += math.gcd(ab,c)
print(gcdsum)

Solution (Python):
import math
K=int(input())
k=0
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)
            d=math.gcd(d,c)
            k+=d
print(k)

Solution (Python):
from math import gcd
K = int(input())
N = range(1, K+1)
print(sum([gcd(gcd(a, b), c) for a in N for b in N for c in N]))

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]
 
sys.setrecursionlimit(1000000)
mod = 1000000007
 
def solve():
    def gcd(a,b):
        if a == 0:
            return b
        return gcd(b%a, a)
    k = I()
    ans = 0
    for a in range(1,k+1):
        for b in range(1,k+1):
            g = gcd(a,b)
            for c in range(1,k+1):
                ans += gcd(g,c)
    print(ans)
    return
 

if __name__ == "__main__":
    solve()

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

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

Solution (Python):
from math import gcd

k = int(input())
num = 0

for a in range(1, k + 1):
  for b in range(1, k + 1):
    c = gcd(a, b)
    num += sum(gcd(c, d) for d in range(1, k + 1))

print(num)

Solution (Python):
import math
K =int(input())
list =[]
for a in range(1,K+1) :
    for b in range(1,K+1) :  
        t = math.gcd(a,b)    
        for c in range(1,K+1) :
           list.append(math.gcd(t,c))  
print(sum(list))

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

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

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

print(ans)

Solution (Python):
import math
k=int(input())
list=[]
for a in range(1,k+1):
  for b in range(1,k+1):
    t=math.gcd(a,b)
    for c in range(1,k+1):
      list.append(math.gcd(t,c))
print(sum(list))

Solution (Python):
import math
 
k = int(input())
 
cache = {}
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans = ans + cache.get( (a,b,c), math.gcd(math.gcd(a, b), c))
print(ans)

Solution (Python):
import itertools
import math

k = int(input())
x = 0
for v in itertools.combinations_with_replacement(list(range(1, k+1)), 3):
    a, b, c = v
    x = x + math.gcd(math.gcd(a,b), c)

y = 0
for v in itertools.combinations(list(range(1, k+1)), 3):
    a, b, c = v
    y = y + math.gcd(math.gcd(a,b), c)

z = k * (1 + k) / 2
print( int(3 * x  + y * 3  -  2 * z))

Solution (Python):
import math

K=int(input())
sum=0

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

        
print(sum)

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

print(res)

Solution (Python):
k=int(input())
def gcd(a,b):
    while a%b!=0:
        c=a%b
        a=b
        b=c
    return b
ans=0
for l in range(k):
    for m in range(l,k):
        x=gcd(m+1,l+1)
        for n in range(m,k):
            ai=gcd(n+1,x)
            if l<m and m<n:
                ans+=6*ai
            elif l==m and m==n:
                ans+=ai
            else:
                ans+=ai*3
            
print(ans)

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

Solution (Python):
import numpy
import math

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

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

def better_gcd(a,b,c):
    tup = set((a,b,c))
    kinds = len(tup)
    if kinds == 3:
        return math.gcd(a, math.gcd(b, c)) * 6
    elif kinds == 2:
        return math.gcd(*tup) * 3
    else:
        return a

ans = 0
cands = list(itertools.combinations_with_replacement(range(1,K+1), 3))
for c in cands:
    ans += better_gcd(*c)
print(ans)

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

import math
import itertools

def better_gcd(a,b,c):
    tup = set((a,b,c))
    kinds = len(tup)
    if kinds == 3:
        return math.gcd(a, math.gcd(b, c)) * 6
    elif kinds == 2:
        return math.gcd(*tup) * 3
    else:
        return a

ans = 0
cands = list(itertools.combinations_with_replacement(range(1,K+1), 3))
for c in cands:
    ans += better_gcd(*c)
print(ans)

Solution (Python):
def gcd(x,y):
  if x<y: x,y=y,x
  while True:
    tmp=x%y
    if tmp==0:
      return y
    x,y=y,tmp

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

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

Solution (Python):
def gcd(x,y):
  if x<y: x,y=y,x
  while True:
    tmp=x%y
    if tmp==0:
      return y
    x,y=y,tmp

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

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


def main():
    K = int(input())
    gcd_memo = [[0 for _ in range(K + 1)] for _ in range(K + 1)]
    for a in range(1, K + 1):
        for b in range(a, K + 1):
            left, right = max([a, b]), min([a, b])
            gcd_ab = gcd(left, right)
            gcd_memo[a][b] = gcd_ab
            gcd_memo[b][a] = gcd_ab
    answer = 0
    for a in range(1, K + 1):
        for b in range(1, K + 1):
            gcd_ab = gcd_memo[a][b]
            answer += sum(gcd_memo[gcd_ab])
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):

import math

from itertools import product as prod




ii = lambda:int(input())
li = lambda:list(map(int,input().split()))

def main(k):
    res = 0
    for item in prod(range(1,k+1),repeat=3):
        res += calc(item)
    return res
        
def calc(item):
    a,b,c = item
    return math.gcd(a,math.gcd(b,c))

k = ii()
print(main(k))

Solution (Python):
import math

K = int(input())

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        d = math.gcd(a, b)
        for c in range(1, K+1):
            ans += math.gcd(c, d)
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
def main():
    K = int(input())
    x=0
    for i in range(1,K+1):
        for j in range(1, K+1):
            for k in range(1,K+1):
                x = x + math.gcd(i, math.gcd(j,k))
    print(x)
main()

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

Solution (Python):



import math

K = int(input())


memo = [[None for _ in range(201)]  for _ in range(201)]
for i in range(1,201):
    for j in range(1,201):
        memo[i][j] = math.gcd(i,j)

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        tmp = memo[a][b]
        for c in range(1, K+1):
            ans += memo[tmp][c]


print(ans)

Solution (Python):
import math
from functools import reduce

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

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

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

Solution (Python):
def main():
    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)
 
 
if __name__ == '__main__':
    main()

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


k = int(input())

count =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:
                if b ==c:
                    count += c
                else:
                    count +=3*gcd(b,c)
            else:
                if b == c:
                    count += 3*gcd(a,b)
                else:
                    tmp = gcd(b,c)
                    count += 6*gcd(a,tmp)


print(count)

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

Solution (Python):
def gcd(m,n):
    while (m % n != 0):
        n,m = m%n,n
    return(n)


k = int(input())
s = 0
for a in range(1,k+1):
    for b in range(a,k+1):
        t = gcd(a,b)
        for c in range(b,k+1):
            v = gcd(t,c)
            l = len(set([a,b,c]))
            if(l == 1):s += v
            elif(l == 2):s += v * 3
            else:s += v * 6
print(s)

Solution (Python):
n=int(input())
 
import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
  
ans=0
for a in range(1,n+1):
    for b in range(1,n+1):
        for c in range(1,n+1):
            
            ans+=gcd(a,b,c)  
print(ans)

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

def gcd2(a,b):
    if b==0:
        return a
    return gcd2(b,a%b)
def gcd3(a,b,c):
    return gcd2(gcd2(a,b),c)

for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            if i==j==k:
                ans+=gcd3(i,j,k)
            elif i==j or j==k:
                ans+=gcd3(i,j,k)*3
            else:
                ans+=gcd3(i,j,k)*6

print(ans)

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

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

print(result)

Solution (Python):
import math
import itertools
K=int(input())
l=list(itertools.combinations_with_replacement(range(1,K+1),3))
S=0
for i in l:
    a=i[0]
    b=i[1]
    c=i[2]
    x=math.gcd(a,b)
    if a==b==c:
        S+=math.gcd(x,c)
    elif a==b or b==c or c==a:
        S+=math.gcd(x,c)*3
    else:
        S+=math.gcd(x,c)*6   
print(S)

Solution (Python):
import math
from functools import reduce

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

n = int(input())
m = 0

for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            m += gcd(i,j,k)
print(m)

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

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

print(ans)

Solution (Python):
from math import gcd
k = int(input()) + 1
total = 0

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

print(total)

Solution (Python):
from math import gcd
k = int(input())
total = 0

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

print(total)

Solution (Python):

import math
k = int(input())
s = 0
box = [0]*(k+1)
for l in range (1,k+1):
     for m in range (1, k+1):
          box[math.gcd(l,m)] += 1
for l in range (1,k+1):
     for n in range (1, k+1):
          s += math.gcd(l,n)*box[l]
print(s)

Solution (Python):
def main():
    k = int(input())
    gcds = []
    for i in range(1, k+1):
        for j in range(1, k+1):
            gcds.append(gcd(i, j))
    ans = {i:0 for i in set(gcds)}
    for i in gcds:
        ans[i] += 1
    out = 0
    for i, v in ans.items():
        for j in range(1, k+1):
            out += gcd(i, j)*v
    print(out)

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

if __name__ == "__main__":
    main()

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

import math

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):
import math
n=int(input())

def gcd2(a,b,c):
    d=math.gcd(a,b)
    e=math.gcd(c,d)
    return e
    
s=0
s1=0
s2=0
s3=0

for i in range(1,n+1):
    s1+=i
    for i2 in range(i+1,n+1):
        s2+=math.gcd(i,i2)
        for i3 in range(i2+1,n+1):
            s3+=gcd2(i,i2,i3)

s=s1+6*s2+6*s3

print(s)

Solution (Python):
import math

K = int(input())

sum = 0

for a in range(1,K + 1):
    sum += a
    
    for b in range(a + 1,K + 1):
        gcd2_sum = math.gcd(a, b) * 3 * 2
        sum += gcd2_sum
        
        for c in range(b + 1, K + 1):
            gcd3_sum = math.gcd(math.gcd(a, b), c) *  6
            sum += gcd3_sum
            
print(sum)

Solution (Python):
import math

K = int(input())

sum = 0

for a in range(K):
    sum += a + 1
    
    for b in range(K):
        if a < b:
            gcd2_sum = math.gcd(a + 1, b + 1) * 3 * 2
            sum += gcd2_sum
            
            for c in range(K):
                if b < c:
                    gcd3_sum = math.gcd(math.gcd(a + 1, b + 1), c + 1) *  6
                    sum += gcd3_sum
                    
print(sum)

Solution (Python):
import math
import itertools
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
  
k = int(input())
count = 0
list_k = [i for i in range(1,k+1)]


count += k*(k + 1)/2

combi2 = itertools.combinations(list_k,2)
for x in list(combi2):
  count += math.gcd(x[0],x[1]) * 6

combi3 = itertools.combinations(list_k,3)
for x in list(combi3):
  count += gcd(x[0],x[1],x[2]) * 6
print(int(count))

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

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

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

Solution (Python):
def gcd(a,b):
    if(a%b==0):
        return b
    else:
        return gcd(b,a%b)
 
k = int(input())
val = [[0]*(k+1) for i in range(k+1)]
sum = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        if(val[i][j] == 0):
            val[i][j] = gcd(i,j)
        for l in range(1,k+1):
            if(val[val[i][j]][l] == 0):
                val[val[i][j]][l] = gcd(val[i][j],l)
            sum = sum + val[val[i][j]][l]
 
print(sum)

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


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

print(sum)

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

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

            if a != b and b != c and a != c:
                tmp *= 2
            if a!=b or b!=c:
                tmp *= 3
            sum += tmp

print(sum)

Solution (Python):
import math
k = int(input())
s = 0
box = [0]*(k+1)
for l in range (1,k+1):
     for m in range (1, k+1):
          box[math.gcd(l,m)] += 1
for l in range (1,k+1):
     for n in range (1, k+1):
          s += math.gcd(l,n)*box[l]
print(s)

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

k = int(input())
ans = []
tmp = [gcd(i+1, j+1) for i in range(k) for j in range(k)]
print(sum([gcd(tmp[i], j+1) for i in range(len(tmp)) for j in range(k)]))

Solution (Python):
import math
from functools import reduce

K=int(input())

ans=K*(1+K)/2
for i in range(1, K+1):
    for j in range(i+1, K+1):
        ans+=math.gcd(i,j)*6
        for k in range(j+1,K+1):
            ans+=reduce(math.gcd, [i,j,k])*6
print(str(int(ans)))

Solution (Python):
import math

K = int(input())

dp = [[0] * 201 for _ in range(201)]

def dp_gcds(x,y):
    if dp[x][y] != 0:
        n = dp[x][y]
    else:
        n = math.gcd(x,y)
        dp[x][y] = n
        dp[y][x] = n
    return n
    
def gcds(x,y,z):
    n1 = dp_gcds(x,y)
    n2 = dp_gcds(n1,z)
    return n2

total = 0
for i in range(1,K+1):
    for j in range(1, K+1):
        for t in range(1, K+1):
            total += gcds(i,j,t)
print(total)