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

class abc_162:
    
    def __init__(self):
        pass
        
    def C(self):
        K=int(input())
        sum_gcd=0
        
        for i in range(1,K+1):
            for j in range(1,K+1):
                for k in range(1,K+1):
                    sum_gcd+=self.gcd(i,j,k)
        
        print(sum_gcd) 


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


if __name__=='__main__':
    obj=abc_162()
    obj.C()

Solution (Python):
import math
from functools import reduce

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

n = int(input())

answer = 0.0

for i in range(1,n+1):
  
  for j in range(1,n+1):
    
    for h in range(1,n+1):
      f = gcd(i,j,h)
      answer += f
      
print(int(answer))

Solution (Python):
N = int(input())
N = N+1
sum = 0

from math import gcd

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

print( sum )

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

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

Solution (Python):
from itertools import combinations
import math
n = int(input())
ans = 0
for r in range(1,4): 
    if r>n:
        break
    for x  in combinations([x+1 for x in range(n)],r):
        if len(x)==1:
            ans += x[0]
        elif len(x)==2:
            ans += math.gcd(x[0],x[1])*6
        else:
            tmp = math.gcd(x[0],x[1])
            ans += math.gcd(x[2],tmp)*6
print(ans)

Solution (Python):


from sys import stdin

import time
import numpy as np
import math




temp = stdin.readline().split()
N = int(temp[0])+1

out = 0
for i in range(1,N):
    for j in range(1,N):
        part = np.gcd(j,i)
        
        out += np.sum(np.gcd(part,np.arange(1,N)))
print(out)

Solution (Python):
dic={}
def gcd(x,y):
  if x<y:
    a=x
    x=y
    y=a
  t=(x,y)
  if t in dic:
    return dic[t]
  else:
    while y!=0:
      a=x%y
      x=y
      y=a
    dic[t]=x
    return x

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

print(s)

Solution (Python):
import math
def gcd_arg3(a,b,c):
    return math.gcd(a,math.gcd(b,c))

k = int(input())

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

print(sum)

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):
      l = len(set([a, b, c]))
      if l==1:
        num = 1
      elif l==2:
        num = 3
      elif l==3:
        num = 6
      sum += gcd(a, b, c)*num
print(sum)

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

n = int(input());

res = 0;

for a in range(1, n + 1):
    for b in range(1, n + 1):
        g = gcd(a, b);
        for c in range(1, n + 1):
            res += gcd(g, c);

print(res);

Solution (Python):
def gcd(p, q):
  while q != 0:
    r = p % q
    p = q
    q = r
  return p

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


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

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

def main():
    sum = 0
    K = int(input())
    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 += math.gcd(tmp, k)
    print(sum)

if __name__ == "__main__":
    main()

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

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

Solution (Python):
import math

K = int(input())

ans = 0
for x in range(1, K + 1, 1):
    for y in range(1, K + 1, 1):
        ans = ans + sum(list(map(lambda z: math.gcd(math.gcd(x, y), z), range(1, K+1, 1))))

print(ans)

Solution (Python):
import math

t = int (input())
sum = 0

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

print (sum)

Solution (Python):
import math
from itertools import product

K=int(input())
s=0
for a,b,c in product(range(1,K+1), repeat=3):
    	s+=math.gcd(math.gcd(b,c),a)
print(s)

Solution (Python):
import math


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

for num_a in range(1,K+1):
	for num_b in range(1,K+1):
		num_d=math.gcd(num_a,num_b)
		for num_c in range(1,K+1):
			num_e=math.gcd(num_c,num_d)
			sum=sum+num_e
			
print(sum)

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

Solution (Python):
import os
from math import gcd


def main():
        k = int(input())
        result = 0
        for i in range(1,k+1):
                for j in range(1,k+1):
                        t = gcd(i,j)
                        for l in range(1,k+1):
                                result += gcd(t,l)
        print(result)
    

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

K = int(input())
s = 0
for i in range(1,K+1):
    for j in range(i,K+1):
        temp = math.gcd(i,j)
        for k in range(1,K+1):
            s += math.gcd(temp,k)
s = s*2

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

print(s)

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

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

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

print(s)

Solution (Python):
import math
import itertools
n = range(1,int(input())+1)
ppp = list(itertools.combinations(n, 3))
pp = list(itertools.combinations(n, 2))
asum,bsum,csum = 0,0,0
for p in ppp:
  asum+=math.gcd(math.gcd(p[0],p[1]),p[2])

for p in pp:
  bsum+=math.gcd(p[0],p[1])

for p in n:
  csum+=p

print(asum*6+bsum*6+csum)

Solution (Python):
import sys
import numpy as np

from math import gcd

N = int(sys.stdin.readline())
ans = 0
"""
dp = np.zeros((N+1, N+1))
def gcd(a, b):
    if a < b:
        a, b = b, a
    
    if dp[a][b] != 0:
        return dp[a][b]

    while b>0:
        a, b = b, a % b
    
    dp[a][b] = a
    return a
"""
for i in range(1,N+1):
    for j in range(1,N+1):
        temp = gcd(i, j)
        for k in range(1,N+1):
            ans += gcd(temp, 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(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

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

print(ans)

Solution (Python):
from math import gcd


def resolve():
    n = int(input())
    ans = 0
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            a = gcd(i, j)
            for k in range(1, n + 1):
                ans += gcd(a, k)

    print(ans)


resolve()

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

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

total = 0

for a in range(1,k+1):
    for b in range(1,k+1):
        subg = gcd(a,b)
        subtotal = 0
        for c in range(1,k+1):
            subtotal += gcd(subg, c)
        total += subtotal

print(total)

Solution (Python):
import math

number = int(input()) + 1
ans = 0

for i in range(1,number):
    for j in range(1,number):
        temp = math.gcd(i,j)
        for k in range(1,number):
            temp_ans = math.gcd(temp,k)
            ans += temp_ans

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(k):
    for b in range(a+1):
        for c in range(b+1):
            if a == b and b == c:
                sum+=gcd(a+1, b+1, c+1)
            elif a!=b and b!=c and c!=a:
                sum += 6*gcd(a+1, b+1, c+1)
            else:
                sum += 3*gcd(a+1, b+1, c+1)
print(sum)

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

print(sum)

Solution (Python):
import sys
import os
from io import BytesIO, IOBase






'''def sieve(n):
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * p, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r'''


'''def divs(n, start=1):
    divisors = []
    for i in range(start, int(n**.5) + 1):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return len(divisors)'''


'''def divn(n, primes):
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t
    return divs_number'''


'''def flin(d, x, default=-1):
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return (default, default)
    else:
        return (left, right)'''


'''def xor1_n(n):
    d={0:n,1:1,2:n+1,3:0}
    return d[n&3]'''

def cel(n, k): return n // k + (n % k != 0)
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def prr(a, sep=' '): print(sep.join(map(str, a)))
def dd(): return defaultdict(int)
def ddl(): return defaultdict(list)
def ddd(): return defaultdict(defaultdict(int))


 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
	newlines = 0
 
	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = "x" in file.mode or "r" not in file.mode
		self.write = self.buffer.write if self.writable else None
 
	def read(self):
			while True:
					b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
					if not b:
							break
					ptr = self.buffer.tell()
					self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
			self.newlines = 0
			return self.buffer.read()
 
	def readline(self):
			while self.newlines == 0:
					b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
					self.newlines = b.count(b"\n") + (not b)
					ptr = self.buffer.tell()
					self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
			self.newlines -= 1
			return self.buffer.readline()
 
	def flush(self):
			if self.writable:
					os.write(self._fd, self.buffer.getvalue())
					self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
	def __init__(self, file):
			self.buffer = FastIO(file)
			self.flush = self.buffer.flush
			self.writable = self.buffer.writable
			self.write = lambda s: self.buffer.write(s.encode("ascii"))
			self.read = lambda: self.buffer.read().decode("ascii")
			self.readline = lambda: self.buffer.readline().decode("ascii")
 

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

from collections import defaultdict 


from math import gcd















k=ii()
ans=0
d2,d3=dd(),dd()
for i in range(1,k+1):
    for j in range(1,k+1):
        tmp=gcd(i,j)
        for l in range(1,k+1):
            ans+=gcd(tmp,l)
print(ans)

Solution (Python):
import math

K=int(input())
s=0
for a in range(1,K+1):
	for b in range(1,K+1):
		s1=math.gcd(a,b)
		for c in range(1,K+1):
			s=s+math.gcd(s1,c)
print(int(s))

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

ans = 0
a=[]
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):
			ans+=math.gcd(tmp,k)

print(ans)

Solution (Python):
k = int(input())
d = [0]*(k+1)
for i in range(1, k+1):
    d[i] = pow(k//i, 3)

for i in reversed(range(1, k+1)):
    for j in range(2*i, k+1, i):
        d[i] -= d[j]

ans = 0
for i in range(1, k+1):
    ans += i*d[i]
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):
        temp = math.gcd(i, j)
        for k in range(1, K+1):
            ans += math.gcd(temp, k)

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np
 
K = INT()
sum = 0
 
for n in range(1, K+1):
  for m in range(1, K+1):
    sum1 = gcd(n, m)
    for l in range(1, K+1):
      sum += gcd(l, sum1)
 
print(sum)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np
 
K = INT()
sum = 0
 
for n in range(K):
  for m in range(K):
    sum1 = gcd(n+1, m+1)
    for l in range(K):
      sum += gcd(l+1, sum1)
 
print(sum)

Solution (Python):
from math import gcd
def INT(): return int(input())
 
 
K = INT()
sum = 0
 
for n in range(1, K+1):
  for m in range(1, K+1):
    for l in range(1, K+1):
      sum += gcd(gcd(n, m), l)
 
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):
		temp = math.gcd(i,j)
		for m in range(1,K+1):
			sum = sum + math.gcd(temp,m)

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

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

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

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

sum = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        temp = math.gcd(i,j)
        for m in range(1,K+1):
            sum = sum+math.gcd(m,temp)
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):
        a=math.gcd(i,j)
        for k in range(1,K+1):
            b=math.gcd(a, k)
            sum = sum + b

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

Solution (Python):
import sys
input = sys.stdin.readline
def main():
   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)

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

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
l=[]

def gcd(a,b):
  a,b=max(a,b),min(a,b)
  if a%b==0:
    return b
  else:
    return gcd(b,a%b)
  
for i in range(1,n+1):
  for j in range(1,n+1):
    l.append(gcd(i,j))
    
ans=0
for i in range(1,n+1):
  for j in l:
    ans+=gcd(i,j)
    
print(ans)

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

memo={}
def gcd(a,b):
    if a<b:
        a,b=b,a

    aa=a
    bb=b
    if (a,b) in memo.keys():
        return memo[a,b]
    while b != 0:
        a,b, = b, a%b
    memo[aa,bb]=a
    return a





memo3={}

def gcd3(a,b,c):
    if a>b:
        a,b = b,a
    if a>c:
        a,c = c,a
    if b>c:
        b,c = c,b
    if (a,b,c) in memo3.keys():
        return memo3[(a,b,c)]
    
    g = gcd(gcd(a,b),c)
    memo3[(a,b,c)]=g
    return g


sum=0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            
            if i==j & j==k:
                sum += gcd3(i,j,k)
                continue
            if i==j & j!=k:
                sum += gcd3(i,j,k)*3
                continue
            if i!=j & j==k:
                sum += gcd3(i,j,k)*3
                continue
            sum += gcd3(i,j,k)*6
print(sum)

Solution (Python):
from os import path
if(path.exists('C:/Users/prana/Desktop/sublime/input.txt')):
    import sys
    sys.stdin = open("C:/Users/prana/Desktop/sublime/input.txt","r")
    sys.stdout = open("C:/Users/prana/Desktop/sublime/output.txt","w")

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

test_case = 1
while(test_case):
    solve()
    test_case -= 1

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

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

Solution (Python):
from math import gcd

n=int(input().strip())

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

Solution (Python):
def gcd(a,b):






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

N = int(input())
tmp = list()
s = 0

for i in range(1,N + 1):
  for j in range(1,N + 1):
      a = gcd(i,j)
      tmp.append(a)

for aTmp in tmp:
  for j in range(1,N + 1):
      a = gcd(aTmp,j)
      s += a

print(s)

Solution (Python):
import sys
input = sys.stdin.readline

import math

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from math import gcd
K = int(input())
sum_gcd = [0]*201
ans = 0
 
for i in range(1,K+1):
  for j in range(1,K+1):
    sum_gcd[gcd(i,j)] += 1
for i in range(1,K+1):
  for k in range(1,K+1):
    ans += sum_gcd[i]*gcd(i,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):
        t = math.gcd(a, b)
        for c in range(1, k+1):
            ans += math.gcd(t, c)
print(ans)

Solution (Python):

from math import gcd

K = int(input())
result = 0
for i in range(1, K + 1):
	for j in range(1, K + 1):
		for k in range(1, K + 1):
			result += gcd(gcd(i, j), k)

print(result)

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 l in range(1, k+1):
      ans += math.gcd(tmp, l)
print(ans)

Solution (Python):
from math import gcd

K = int(input())
lst = []
for x in range(1, K + 1):
    for y in range(1, K + 1):
        for z in range(1, K + 1):
            lst.append(gcd(gcd(x, y), z))

print(sum(lst))

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
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 l in range(1, k+1):
      ans += math.gcd(tmp, l)
print(ans)

Solution (Python):
import math 

K = int(input())

def sol(K):
    res = 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):
                res += math.gcd(k, t)

    return res
  
print(sol(K))

Solution (Python):
import math

n = int(input())
answer = 0

for a in range(1,n+1):
    for b in range(1,n+1):
        t = math.gcd(a,b)
        for c in range(1,n+1):
            answer += math.gcd(t,c)
print(answer)

Solution (Python):
import math

k = int(input())
n = 0

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

print(n)

Solution (Python):


k = int(input())
count = 0

def gcd(a,b):
    if a >= b:
        k1, k2 = a, b
    elif a < b:
        k1, k2 = b, a

    r = k1 % k2
    if r != 0:
        return gcd(k2,r)
    elif r == 0:
        return k2

for a in range(1,k+1):

    for b in range(1,a+1):

        f = gcd(a,b)

        for c in range(1,b+1):

            g = gcd(f,c)
            
            if a == b and b != c:
                count += g * 3
            elif b == c and c != a:
                count += g * 3
            elif c == a and a != b:
                count += g * 3
            elif a == b and b == c:
                count += g
            else:
                count += g * 6

print("{}".format(count))

Solution (Python):
import math
from functools import reduce

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

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

def gcd(a,b):
   while b != 0:
       a, b = b, a % b
       if b ==0:
           return a
A1 = [0,0]
A2 = [0,0,0]
for i in range(1, K+1):
    S = S + i

if K > 1:
    for j in range(1, K):
        A1[0] =  j
        for k in range(j+1,K+1):
            A1[1] = k
            S += 6 * gcd(A1[1],A1[0])

if K > 2:
    for i1 in range(1, K-1):
        A2[0] = i1
        for k1 in range(i1+1, K):
            A2[1] = k1
            for j1 in range(k1+1,K+1):
                A2[2] = j1
                G3 = gcd(A2[2],A2[1])
                if G3 >= A2[0]:
                    S += 6 * gcd(G3,A2[0])
                else:
                    S += 6 * gcd(A2[0],G3)
print(S)

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

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

Solution (Python):
import math
N = int(input())
ans = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        ans_ = math.gcd(i,j)
        for k in range(1,N+1):
            ans += math.gcd(ans_,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):
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):
K = int(input())

table_gcd = [[0 for i in range(K)] for j in range(K)]
table_num = [0 for i in range(K)]

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

for a in range(0, K) :
  for b in range(0, a+1) :
    if(a == b) :
      table_gcd[a][b] = a+1
      table_gcd[b][a] = a+1
      table_num[a] += 1
    else :
      cd = gcd(a+1, b+1)
      table_gcd[a][b] = cd
      table_gcd[b][a] = cd
      table_num[cd-1] += 2
    
ans = 0
for c in range(0, K) :
  for cd in range(0, K) :
    ans += table_num[cd] * table_gcd[c][cd]
  
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):
        ab = gcd(a, b)
        for c in range(1, K+1):
            ans += gcd(ab, c)
print(ans)

Solution (Python):
from math import gcd

k = int(input())

n = 0

for i in range(1, k + 1):
    for i2 in range(1, k + 1):
        for i3 in range(1, k + 1):
            n += gcd(gcd(i, i2), i3)

print(n)

Solution (Python):
import sys
input=lambda: sys.stdin.readline().rstrip()
k=int(input())
def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
def ggcd(a,b,c):
  return gcd(gcd(a,b),c)
ans=0
for a in range(k):
  for b in range(k):
    for c in range(k):
      ans+=ggcd(a+1,b+1,c+1)
print(ans)

Solution (Python):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
    
K=int(input())
sum=0
for i in range(1, K+1):
    for j in range(i+1, K+1):
        for k in range(j+1, K+1):
            sum += 6*gcd(i, j, k)
for i in range(1, K+1):
    for j in range(i+1, K+1):
        sum += 2*3*gcd(i, j)
sum += int( (K+1)*K/2 )
print(sum)

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

Solution (Python):
MAX_K: int = 200

gt = [[0 for _ in range(MAX_K + 1)] for _ in range(MAX_K + 1)]

def gcd(x: int, y: int) -> int:
    if gt[x][y] > 0:
        return gt[x][y]
    ret: int = 0
    if x < y:
        ret = gcd(y, x)
    elif y == 0:
        ret = x
    elif y == 1:
        ret = 1
    else:
        ret = gcd(y, x % y)
    gt[x][y] = ret
    
    return ret

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

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

Solution (Python):
from math import gcd
def gc(a,b,c):
    return gcd(gcd(a,b),c)
k=int(input())
ans=0
for a in range(1,k+1):
    for b in range(1,a+1):
        for c in range(1,b+1):
            x=gc(a,b,c)
            if a!=b and b!=c and c!=a:
                ans+=6*x
            elif a==b and b==c:
                ans+=x
            else:
                ans+=3*x
print(ans)

Solution (Python):
import math

input_num = int(input())
total = 0


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


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