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())
gcd_sum_dic = {}
for i in range(1, k+1):
    gcd_sum_dic[i] = 0
    for j in range(1, k+1):
        gcd_sum_dic[i] += math.gcd(i, j)
ans = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        ans += gcd_sum_dic[math.gcd(i, j)]
print(ans)

Solution (Python):
def main():
    from math import gcd

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

    print(cal)


main()

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

ans = 0
for i in range(1,n+1):
    for j in range(i, n+1):
        for k in range(j, n+1):
            if i == j and j == k:
                ans += i
            
            elif len({i,j,k}) == 2:
                ans += math.gcd(math.gcd(i,j),k)*3
            
            elif len({i,j,k}) == 3:
                ans += math.gcd(math.gcd(i,j),k)*6
        
print(ans)

Solution (Python):
from math import gcd
K=int(input())
ans=0

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

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

Solution (Python):
import math    

K = int(input())
ans = 0

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

Solution (Python):
def gcd(a, b):
  if b > a:
    temp = b
    b = a
    a = temp
  if a % b == 0:
    return b
  else:
    return gcd(b, a % b)
def sum_of_gcd(k):
  ans = 0
  for i in range(1, k + 1):
    for j in range(1, k + 1):
      for k in range(1, k + 1):
        if i < j and j < k:
          ans += gcd(i, gcd(j, k)) * 6
        elif i < j and j == k:
          ans += gcd(i, gcd(j, k)) * 3
        elif i == j and j < k:
          ans += gcd(i, gcd(j, k)) * 3
        elif i == j and j == k:
          ans += gcd(i, gcd(j, k))
  return ans
 
n = int(input())
print(sum_of_gcd(n))

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

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

Solution (Python):
from math import gcd

K = int(input())

ans = 0

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

Solution (Python):
from sys import stdin
import itertools
from math import gcd


























K = int(input())

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

Solution (Python):
from sys import stdin

def gcd(a,b):
    if a<b:
        tmp=a
        a=b
        b=tmp
    r=a%b
    while r!=0:
        a=b
        b=r
        r=a%b
    return b

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,gcd(j,k))
print(str(ans)+"\n")

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

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

Solution (Python):
import math
from functools import reduce

k = int(input())

ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            ans += reduce(math.gcd, [a, b, c])

print(ans)

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

Solution (Python):
import numpy as np

K = int(input())
r = np.arange(1, K + 1)
print(np.sum(np.gcd.outer(np.gcd.outer(r, r), r)))

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

k = int(input())

ans = 0
for ptn in product(range(1, k + 1), repeat=3):
    ans += reduce(gcd, ptn)

print(ans)

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

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

Solution (Python):
K = int(input())+1
sum_gcd = 0
def gcd(p,q):
    if p % q == 0:
        return q
    return gcd(q,p%q)
for a in range(1,K):
    sum_gcd += a
    for b in range(a+1,K):
        gcd_ab =gcd(a,b)
        sum_gcd += gcd_ab*6
        for c in range(b+1,K):
            sum_gcd +=gcd(gcd_ab,c)*6
print(sum_gcd)

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

log = {}
K = int(input())
sum_gcd = 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(gcd(a, b), c)
print(sum_gcd)

Solution (Python):
n = int(input())
ans = 0
t = 0
import math
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())
ans = 0
from math import gcd
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):
    x = gcd(i,j)
    for l in range(1,k+1):
      ans += gcd(x,l)
print(ans)

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

print(ans)

Solution (Python):
import math
k = int(input())
ans = 0
for i in range(k):
  for j in range(k):
    tmp = math.gcd(i + 1, j + 1)
    for l in range(k):
      ans += math.gcd(tmp, l + 1)
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):
        sum += math.gcd(i, j)
        if j == K:
            break
        else:
            for k in range(j + 1, K + 1):
                sum += math.gcd(i, math.gcd(j, k)) * 2

print(sum)

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

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


s = 0
n = int(input())


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

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

s = s*6 + int(0.5 * n * (n+1))
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(a+1, math.gcd(b+1, c+1))
print(ans)

Solution (Python):
import math

k = int(input())
def ans():
    sum = 0
    for l in range(1,k+1):
        for m in range(1,k+1):
            for n in range(1,k+1):
                sum += math.gcd(math.gcd(l,m),n)
    return(sum)
print(ans())

Solution (Python):
import math

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

Solution (Python):
import math
from numba import jit

k = int(input())

@jit
def ans():
    sum = 0
    temp = 0
    for l in range(1,k+1):
        for m in range(1,k+1):
            temp = math.gcd(l,m)
            for n in range(1,k+1):
                sum += math.gcd(temp,n)
    return(sum)
print(ans())

Solution (Python):
import math

k = int(input())
def ans():
    sum = 0
    temp = 0
    for l in range(1,k+1):
        for m in range(1,k+1):
            temp = math.gcd(l,m)
            for n in range(1,k+1):
                sum += math.gcd(temp,n)
    return(sum)
print(ans())

Solution (Python):
import math
from numba import jit

k = int(input())

@jit
def ans():
    sum = 0
    temp = 0
    for l in range(1,k+1):
        for m in range(1,k+1):
            temp = math.gcd(l,m)
            for n in range(1,k+1):
                sum += math.gcd(temp,n)
    return(sum)
print(ans())

Solution (Python):
import math
from numba import jit

k = int(input())

@jit
def ans():
    sum = 0
    for l in range(1,k+1):
        for m in range(1,k+1):
            for n in range(1,k+1):
                sum += math.gcd(math.gcd(l,m),n)
    return(sum)
print(ans())

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

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

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())
ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            abc_gcd = gcd_list([a,b,c])
            
            ans += abc_gcd

print(ans)

Solution (Python):

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

K = int(input()) + 1
mydict = {}


ans = 0
for h in range(1, K):
  ans += gcd(h,gcd(h,h))

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

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

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):
        gcd_sum[i] += gcd(i,j)
        
        
'''
       
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)

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

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

Solution (Python):
import math


temp = 0
K = int(input())
sum = 0
for A in range(1,K+1):
    for B in range(1,K+1):
        temp = math.gcd(A,B)
        for C in range(1,K+1):
            sum = sum + math.gcd(temp,C)
print(sum)

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

Solution (Python):
import math

def gcd(n1,n2,n3):
    return math.gcd(math.gcd(n1,n2), n3)
    
ans = 0
K = int(input())
r = range(1, K+1)

print(sum([gcd(x1,x2,x3) for x1 in r for x2 in r for x3 in r ]))

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

Solution (Python):
from sys import stdin, stdout
import math as m
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()

def tgcd(a, b, c):
	d = m.gcd(a, b)
	return m.gcd(d, c)    

def main():
	k = int(rl())
	ans = 0
	for a in range(1, k+1):
		for b in range(1, k+1):
			for c in range(1, k+1):
				ans += tgcd(a, b, c)
	stdout.write(str(ans));stdout.write("\n")
	stdout.close()

if __name__ == "__main__":
	main()

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

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

mat = [[0 for i in range(201)] for j in range(201)]

for i in range(201):
    for j in range(201):
        mat[i][j] = gcd(i, j)

sm = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            sm += mat[mat[a][b]][c]

print(sm)

Solution (Python):
a=int(input())
counter=0
for i in range(1,a+1):
    for j in range(i,a+1):
        for k in range(j,a+1):
            if i==j and j==k:
                times=1
            elif i!=j and j!=k and k!=i:
                times=6 
            else:
                times=3
            
            for l in range(i,0,-1): 
                if i%l==0 and j%l==0 and k%l==0:
                    counter+=(l*times)
                    break
print(counter)

Solution (Python):
from math import gcd
from numba import njit

K = int(input())

@njit
def solve():
    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)
    return ans
print(solve())

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 numba import njit
from math import gcd

K = int(input())

@njit
def solve():
    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)
    return ans

print(solve())

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

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 itertools
K=int(input())
 
result=[]
count=0
cnt=0
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
 
 
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      ans1=gcd(j,k)
      count=gcd(i,ans1)
      cnt+=count
      
print(cnt)

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

Solution (Python):
from math import gcd

K = int(input())

memo = []
memolist = []
for i in range(1,K+1):
    if i != 1:
        memo.append(memolist)
    memolist = []
    for j in range(1,K+1):
        memolist.append(gcd(i,j))
memo.append(memolist)

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(memo[i-1][j-1],k)

print(result)

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

Solution (Python):
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    ret = 0
    for a in range(1, N + 1):
        for b in range(1, N + 1):
            q = math.gcd(a, b)
            for c in range(1, N + 1):
                ret += math.gcd(q, c)
    print(ret)


if __name__ == '__main__':
    main()

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


print(sum)

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

for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            a=math.gcd(i,j)
            a=math.gcd(a,k)
            if i==j and i==k:
              ans=ans+a
            elif i==j or i==k or j==k:
              ans=ans+3*a
            else:
              ans=ans+6*a
print(ans)

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

def resolve():
	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(i, gcd(j, k))
	print(ans)

resolve()

Solution (Python):
from math import gcd 

k = int(input())

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

print(s)

Solution (Python):
import fractions
from functools import reduce
import itertools
import math

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

K = int(input())

if K == 1:
    ans = 1
elif K == 2:
    ans = 9
else:
    ans = 0
    for i in range(1, K+1):
        ans += i
        for j in range(i+1, K+1):
            ans += gcd(i, j) * 6
            for k in range(j+1, K+1):
                ans += gcd(i, j, k) * 6

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())
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 + gcd(a,b,c)
       """
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 math import gcd
k = int(input())

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

Solution (Python):
K = int(input())
sum = 0
class gcd:
    def __init__(self,a,b,c):
        self.a=a
        self.b=b
        self.c=c
        
    def gcds(self):
        if self.a>self.b:
            x=self.a
            y=self.b
        else:
            x=self.b
            y=self.a
            
        while x % y!=0:
            tem_y = y
            y = x % y 
            x = tem_y
       
        gcd_1 = y
        
        if gcd_1>self.c:
            x=gcd_1
            y=self.c
        else:
            x=self.c
            y=gcd_1
            
        while x % y!=0:
            tem_y = y
            y = x % y 
            x = tem_y
       
        return int(y)

for i in range(1,K+1):
    for j in range(i,K+1):
        for l in range(j,K+1):
            if i==j and j==l:
                sum = sum + gcd(i,j,l).gcds()
            elif i != j and j==l:
                sum = sum + gcd(i,j,l).gcds()*3
            elif i==j and j!= l:
                sum = sum + gcd(i,j,l).gcds()*3
            elif i!=j and j!=l:
                sum = sum + gcd(i,j,l).gcds()*6         
            
print(sum)

Solution (Python):
def main():
    s = 0
    n = int(input())
    for i in range(1, n+1):
        for j in range(1, n+1):
            gcd_tmp = gcd(i, j)
            for k in range(1, n+1):
                s += gcd(gcd_tmp, k)
    print(s)


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


if __name__ == "__main__":
    main()

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

Solution (Python):
import sys
import math
K=int(sys.stdin.readline()[:-1])
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(k,math.gcd(i,j))

print(ans)

Solution (Python):
from sys import stdin
import numpy as np


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    K = int(_in[0])  
    
    x_arr = np.arange(1,K+1)
    cnt = np.gcd.outer(np.gcd.outer(x_arr,x_arr),x_arr).sum()
    
    print(cnt)

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

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

Solution (Python):
import math
k=int(input())
total=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for m in range(1,k+1):
            g=math.gcd(i,j)
            g=math.gcd(g,m)
            total+=g
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 m in range(1,k+1):
            g=gcd(i,j)
            g=gcd(g,m)
            total+=g
print(total)

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

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

Solution (Python):
from math import gcd

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

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

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

Solution (Python):
def gcd(x,y):
  if x>y:
    x,y=y,x
  while y%x!=0:
    y,x=x,y%x
  return x

def main():
  K=int(input())
  T=[[0]*-~K for _ in range(K+1)]

  for x in range(1,K+1):
    for y in range(1,K+1):
      T[x][y]=gcd(x,y)

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

  print(t)

main()

Solution (Python):
import math
from functools import lru_cache
from itertools import combinations


@lru_cache(maxsize=None)
def gcd2(a: int, b: int) -> int:
    return math.gcd(a, b)


def gcd3(a: int, b: int, c: int) -> int:
    return gcd2(gcd2(a, b), c)


def main() -> None:
    k = int(input())

    one_to_k = range(1, k + 1)
    s1 = sum(one_to_k)
    s2 = sum(gcd2(a, b) for a, b in combinations(one_to_k, 2))
    s3 = sum(gcd3(a, b, c) for a, b, c in combinations(one_to_k, 3))
    print(s1 + 6 * s2 + 6 * s3)


if __name__ == "__main__":
    main()

Solution (Python):
import math
import collections

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

ans = 0
combination_list = [0, 1, 3, 6]
for p in range(1, k+1):
    for q in range(p, k+1):
        if gcd_table[p-1][q-1] == 0:
            tmp_gcd = math.gcd(p, q)
            gcd_table[p-1][q-1] = tmp_gcd
        else:
            tmp_gcd = gcd_table[p-1][q-1]
        for r in range(q, k+1):
            if gcd_table[q-1][r-1] == 0:
                tmp_gcd_2 = math.gcd(q, r)
                gcd_table[q-1][r-1] = tmp_gcd_2
            else:
                tmp_gcd_2 = gcd_table[q-1][r-1]
            unique_num = len(collections.Counter([p, q, r]))
            ans += math.gcd(tmp_gcd, tmp_gcd_2) * combination_list[unique_num]
print(ans)