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):
N = int(input())
K = [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(K[N-1])

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

Solution (Python):
import math


def agg_gcd(i, j, k):
    gcd = math.gcd(i, j)
    gcd = math.gcd(gcd, k)
    return gcd


K = int(input())

count = 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 and j == k:
                count += agg_gcd(i, j, k)
            elif i == j or j == k:
                count += 3 * agg_gcd(i, j, k)
            else:
                count += 6 * agg_gcd(i, j, k)

print(count)

Solution (Python):
import math
import fractions

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

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

from math import gcd
   
ans = 0
dic = {}
for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            time = len(set([i, j, k]))
            if time==3:
                t=6
            elif time==2:
                t=3
            else:
                t=1
            s = tuple(sorted([i, j, k]))
            if s in dic:
                ans += dic[s]
            else:
                a = gcd(gcd(i, j), k)
                ans += a*t
                dic[s] = a*t
                
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())

ret = 0

my_dict = dict()

for i in range(1, k+1):
    for j in range(1, i+1):
        for l in range(1, j+1):
            if i == j and j == l:
                ret += gcd_list([i, j, l])
            elif i != j and j != l:
                ret += 6 * gcd_list([i, j, l])
            else:
                ret += 3 * gcd_list([i, j, l])


print(ret)

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

Solution (Python):
n = int(input())
res = 0

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

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

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

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

print(ans)

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

def tri_gcd(l):
    return reduce(math.gcd, l)

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

    """
    すべて同じ1
    ２つ同じ3
    すべて異なる6    
    """

    for i in range(1, k+1, 1):
        for j in range(i, k + 1, 1):
            for m in range(j, k + 1, 1):
                if i == j and j == m:
                    ans += tri_gcd([i, j, m])
                elif i == j or j == m:
                    ans += tri_gcd([i, j, m]) * 3
                else:
                    ans += tri_gcd([i, j, m]) * 6

    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2"""
        output = """9"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """200"""
        output = """10813692"""
        self.assertIO(input, output)

if __name__ == "__main__":
    
    resolve()

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


def all_eq(K):
    return K*(K+1)/2

def eq_2(K):
    answer = 0
    for i in range(1, K+1):
        for j in range(i+1, K+1):
            answer =answer +gcd(j,i)
    return answer

def not_eq(K):
    answer = 0
    for i in range(1, K+1):
        for j in range(i+1, K+1):
            for k in range(j+1, K+1):
              answer = answer + gcd(gcd(i,j), k)
    return answer

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

print(int(all_eq(K)+eq_2(K)*6+not_eq(K)*6))

Solution (Python):


import sys
stdin = sys.stdin
from math import gcd

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

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


if __name__ == "__main__":
    main()

Solution (Python):

import sys
import math


def solve(K: int):

    ans = 0
    for a in range(1,K+1):
        for b in range(a,K+1):
            for c in range(b,K+1):
                p=1
                if (a == b) or (b == c) or (a ==c):
                    p+=1
                    if (a==b==c):
                        p+=4
                ans += math.gcd(math.gcd(a,b),c)*(int(6/p))
                
    print(ans)

    return



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

if __name__ == '__main__':
    main()

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

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


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

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

print(ans)

Solution (Python):
import math
from functools import reduce

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

k = int(input())
ans = 0

for i in range(1,k+1):
    ans += i 
    for 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 sys
import math
K=int(input())
gcd_list = [[0 for i in range(K)] for j in range(K)]
ij_list = []
ans = 0

for i in range(1,K+1):
    for j in range(1,K+1):
        ij_list.append(math.gcd(i,j))

for k in range(1,K+1):
    for v in ij_list:
        ans += math.gcd(k,v)


print(ans)

Solution (Python):
import math
from functools import reduce

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

k = int(input())


s = k * (k+1) / 2


for a in range(1, k):
	for b in range(a+1, k+1):
		s = s + 6 * math.gcd(a,b)


for a in range(1, k-1):
	for b in range(a+1, k):
		for c in range(b+1, k+1):
			s = s + 6 * gcd(a, b, c)

print(int(s))

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

print(s)

Solution (Python):
import math
from functools import reduce

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

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)

n = int(input())
total = 0
for i in range(1,n+1):
    for j in range(i,n+1):
        for k in range(j,n+1):
            t = 1
            if i != k and i != j and j!= k:
                t = 6
            elif (i == j and i != k) or (i != j and j == k):
                t = 3
            total += gcd(i,j,k)*t
print(total)

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

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

Solution (Python):
from math import gcd
from collections import defaultdict

N = int(input())

answer = 0

for a in range(1, N + 1):
    for b in range(1, N + 1):
        for c in range(1, N + 1):
            n = gcd(gcd(a, b), c)
            answer += n

print(answer)

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

Solution (Python):



N = int(input())





import itertools
import math
l = []
answer = 0

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

for i in range(N):
    l.append(i+1)
p = itertools.combinations_with_replacement(l, 3)
for i in p:
    a = list(i)
    g = gcd(a[0], a[1])
    ans = gcd(g, a[2])
    if a[0] == a[1] == a[2]:
        answer += ans
    elif (a[0] == a[1] and a[0] !=a[2]) or (a[0] == a[2] and a[0] !=a[1]) or (a[1] == a[2] and a[1] !=a[0]):
        answer += ans*3
    else:
        answer += ans*6
print(answer)

Solution (Python):
import sys, math

k = int(sys.stdin.readline().strip())

stored2 =  [[ [0 for i in range(k+1)] for j in range(k+1)] for z in range(k+1)]
stored = [ [0 for i in range(k+1)] for j in range(k+1)]
def get_gcd(x, y):
    x, y = min(x,y), max(x,y)
    if x == 1:
        return 1
    if stored[x][y] == 0:
        stored[x][y] = math.gcd(x,y)
    return stored[x][y]

res = 0
for x in range(1, k+1):
    for y in range(x, k+1):
        for z in range(y, k+1):
            stored2[x][y][z] = get_gcd(x,get_gcd(y,z))

for x in range(1, k+1):
    for y in range(1, k+1):
        for z in range(1, k+1):
            a,b,c = sorted([x,y,z])
            res += stored2[a][b][c]

print(res)

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

def main():
    import math
    K = int(readline().strip().decode())
    cnt = 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(b, c)
                g = math.gcd(a, tmp)
                cnt += g
    print(cnt)
    return

if __name__ == '__main__':
    main()

Solution (Python):
from math import gcd

k = int(input())
IJ = []

cnt = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        IJ.append(gcd(i, j))

for ij in IJ:
    for k in range(1, k+1):
        cnt += gcd(ij, k)

print(cnt)

Solution (Python):
def main():
    s = 0
    n = int(input())
    gd1s = []
    combs = {}
    for i in range(1, n+1):
        for j in range(1, n+1):
            try:
                gd1 = combs[(i, j)]
                combs[(j, i)] = gd1
                gd1s.append(gd1)
            except:
                gd1 = gcd(i, j)
                gd1s.append(gd1)
                combs[(i, j)] = gd1

    for k in range(1, n+1):
        for g in gd1s:
            s += combs[(g,k)]
    print(s)

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

if __name__ == "__main__":
    main()

Solution (Python):
import math
from functools import reduce
from sys import stdin 
n = int(stdin.readline().rstrip())
def gcd(*numbers):
    return reduce(math.gcd, numbers)
answer = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            answer += gcd(i+1,j+1,k+1)
print(answer)

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

Solution (Python):


import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def gcd(a, b):

    c = min(a, b)
    d = max(a, b)
    r = 0    
    while True:
        r = d % c
        if r == 0:
            break
        d = c
        c = r

    return c

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
    
    (k, ) = [int(e) for e in lines[0].split(" ")]

    return (k, )


def solve(k):

    result = 0
    mem = dict()
    for a in range(1, k+1):
        for b in range(1, k+1):
            for c in range(1, k+1):
                if (b, c) in mem:
                    d = mem[(b, c)] 
                else:
                    d = gcd(b, c)
                    mem[(b, c)] = d

                if (a, d) in mem:
                    e = mem[(a, d)] 
                else:
                    e = gcd(a, d)
                    mem[(a, d)] = e

                result = result + e
    
     
    return  result


def main():
    
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Solution (Python):
k = int(input())
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
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):
K = int(input())
r = [[0]*K for _ in range(K)]
def Euclid(a,b):
    if b == 0:
        return a
    else:
        return Euclid(b,a%b)
ans = 0
for i in range(K):
    for j in range(i,K):
        r[i][j] = Euclid(i+1,j+1)
        for m in range(K):    
            if i == j:
                ans += Euclid(r[i][j],m+1)
            else:
                ans += Euclid(r[i][j],m+1)*2
print(ans)

Solution (Python):
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]


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

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


k = int(input())

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

print(answer)

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




g = [[0 for i in range(k)] for j in range(k)]

s = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        if g[i-1][j-1] == 0:
            x = math.gcd(i, j)
            g[i-1][j-1] = x
            g[j-1][i-1] = x
        a = g[i-1][j-1]
        for l in range(1, k+1):
            if g[a-1][l-1] == 0:
                y = math.gcd(a, l)
                g[a-1][l-1] = y
                g[l-1][a-1] = y
            s += g[a-1][l-1]

print(s)

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


import math
from functools import reduce

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

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):
def gcd2(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd2(b, a % b)


def gcd3(a, b, c):
    return gcd2(gcd2(a, b), c)


k = int(input())
sum = 0


for i in range(1, k + 1):
    sum += gcd3(i, i, i)

for i in range(1, k + 1):
    for j in range(1, k + 1):
        if i == j:
            continue
        else:
            sum += gcd3(i, i, j) * 3

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

print(sum)

Solution (Python):







import math
from functools import reduce
import sys
sys.setrecursionlimit(15000)

n = int(sys.stdin.readline())
sum = 0
def gcd(*numbers):
    return reduce(math.gcd, numbers)
for a in range(1,n+1):
    for b in range(1,n+1):
        for c in range(1,n+1):
            sum += gcd(a,b,c)
print(sum)

Solution (Python):
import math

def main():
    k=int(input())
    
    ans=0
    gcd2=[]
    for i in range(1,k+1):
        for j in range(1,k+1):
           gcd2.append(math.gcd(i,j))
    for i in range(1,k+1):
        for j in gcd2:
            ans+=math.gcd(i,j)
    '''
    for i in range(1,k+1):
        for j in range(1,k+1):
            for k in range(1,k+1):
                a,b,c=map(int,sorted([i,j,k]))
                print(a,b,c)
                if gcds[a][b][c]==0:
                    gcds[a][b][c]=gcd(a,b,c)
                ans+=gcds[a][b][c]
    '''
    print(ans)

if __name__=='__main__':
    main()

Solution (Python):
from math import gcd
import sys
n = int(input())
s=0
a = {197:10290813,198:10493367,199:10611772,200:10813692}
if n>=197:
    print(a[n])
    sys.exit(0)
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            s = s + gcd(gcd(i,j),k)
print(s)

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

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

    
    total = 0

    dp = [[0] * (K + 2) for _ in range(K + 2)]

    sub0 = (K + 1) * K // 2

    sub1 = 0
    for a in range(1, K + 1):
        for b in range(a + 1, K + 1):
            v = gcd(a, b)
            dp[a][b] = v
            sub1 += v

    sub2 = 0
    for a in range(1, K + 1):
        for b in range(a + 1, K + 1):
            ab = dp[a][b]
            for c in range(1, K + 1):
                sub2 += gcd(ab, c)

    total += sub0 + sub1 * 2 + sub2 * 2

    print(total)


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    from math import gcd
    from functools import reduce
    k=int(input())
    res=0
    for i in range(1,k+1):
        for j in range(1,k+1):
            for l in range(1,k+1):
                res+=reduce(gcd,[i,j,l])
    print(res)


if __name__ == '__main__':
    main()

Solution (Python):
import math
from functools import reduce

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

k = int(input())

result = 0

    
        
            

result_1 = 0
for num in range(1, k+1):
    result_1 += num

result_2 = 0
for num_one in range(1, k+1):
    for num_two in range(num_one+1, k+1):
        result_2 += math.gcd(num_one, num_two)

result_2 *= 6

result_3 = 0
for num_one in range(1, k+1):
    for num_two in range(num_one+1, k+1):
        for num_three in range(num_two+1, k+1):
            result_3 += gcd_mul(num_one, num_two, num_three)

result_3 *= 6



result = result_1 + result_2 + result_3
print(result)

Solution (Python):
K = int(input())
import numpy as np
a = np.arange(1, K+1)
b = np.arange(1, K+1)
c = np.arange(1, K+1)
s = np.gcd.outer(a, np.gcd.outer(b, c)).sum()
print(s)

Solution (Python):
import math
k=int(input())
l=[]
r=0
for a in range(1,k+1):
    for b in range(1,k+1):
        l.append(math.gcd(a,b))

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

Solution (Python):
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
K = int(input())
cnt = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            cnt += gcd(a,gcd(b,c))
print(cnt)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

K = int(read())

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

Solution (Python):
import math as m

K = int(input())

res = 0
for a in range(1, K + 1):
    for b in range(a, K + 1):
        for c in range(b, K + 1):
            if a == b == c:
                res += a
            elif (a == b and a != c) or (b == c and b != a) or (a == c and a != b):
                res += m.gcd(max(a, b, c), min(a, b, c)) * 3
            else:
                res += m.gcd(m.gcd(a, b), c) * 6

print(res)

Solution (Python):
import math
def gcd3(a,b,c):
    return math.gcd(math.gcd(a,b),c)
def main():
    K=int(input())
    ans=0
    for i in range(1,K+1):
        for j in range(1,i+1):
            for k in range(1,j+1):
                if i==j and j==k:
                    ans+=i
                elif i!=j and j!=k and k!=i:
                    ans+=gcd3(i,j,k)*6
                else:
                    ans+=gcd3(i,j,k)*3
    print(ans)
if __name__=="__main__":
    main()

Solution (Python):
import math
from functools import reduce

K = int(input())

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

def sieve_of_eratosthenes(n):
	if n == 1:
		return []
	if n == 2:
		return [2]
	candidate = [i for i in range(2, n+1)]
	prime = []
	limit = math.sqrt(n) + 1

	while True:
		p = min(candidate)
		if limit <= p:
			prime.extend(candidate)
			break
		prime.append(p)
		candidate = [i for i in candidate if i % p != 0]
	return prime



ans = 0
l = [[[0 for _ in range(201)]for _ in range(201)]for _ in range(201)]
for i in range(1,K+1):
	for j in range(1,K+1):
		for k in range(1,K+1):
			a = sorted([i,j,k])
			if l[a[0]][a[1]][a[2]] == 0:
				tmp = gcd(i,j,k)
				ans += tmp
				l[a[0]][a[1]][a[2]] = tmp
			else:
				ans += l[a[0]][a[1]][a[2]]
print(ans)

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

import math

answer = 0

for i in range(1, K+1, 1):
  for j in range(1, K+1, 1):
  	g = math.gcd(i, j)
  	for k in range(1, K+1, 1):
  	  if k % g == 0:
  	  	answer += g
  	  elif k == 1 or g == 1:
  	  	answer += 1
  	  else:
  	  	answer += math.gcd(g, k)
else:
  print(answer)

Solution (Python):
import numpy as np

k = int(input())
ar = np.arange(1, k+1)
l = [np.gcd(ar,x) for x in ar]
res = sum([np.gcd(ar,x).sum() for a in l for x in a])
print(res)

Solution (Python):
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(100000)


def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 

P = {}
def gcd(a, b):
    if a > b:
        a, b = b, a
    if (a, b) in P:
        return P[(a, b)]
    
    v = math.gcd(a, b)
    P[(a, b)] = v
    return v


def main():
    K = int(input()) - 1
    A = [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(A[K])


if __name__ == "__main__":
    main()

Solution (Python):
a=[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]
x=int(input())
print(a[x-1])

Solution (Python):
import math

k = int(input())

s = 0
x = []
for a in range(1,k+1):
    for b in range(1,k+1):
        x.append(math.gcd(a,b))
for y in x:
    for c in range(1,k+1):
        s+=math.gcd(y,c)
print(s)

Solution (Python):
import math
from functools import lru_cache

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








K = int(input())
ans = 0
for i in range(K):
    for j in range(K):
        ab = ls_gcd[i+1][j+1]
        t = ls_gcd[ab]
        for k in range(K):
            ans += t[k+1]
print (ans)

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

total = 0
for i in range(k):
    for j in range(k):
        ij_gcd = math.gcd(i+1, j+1)
        if ij_gcd == 1:
            total+=k
            continue
        for l in range(k):
            total+=math.gcd(l+1, ij_gcd)

print(total)

Solution (Python):
import math

N = input()
N = int(N)

gcds = []

for i in range(0,N):
  gcds.append([])
  for j in range(0,N):
    gcds[i].append(math.gcd(i+1,j+1))


sum = 0
for i in range(0,N):
    for j in range(0,N):
        for k in range(0,N):
            sum += gcds[ gcds[i][j] -1 ][k]

print(sum)

Solution (Python):
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
counter = 0
n = int(input())
list = [0] * (n + 1)
for l in range(1, n + 1):
    for m in range(1, n + 1):
        list[gcd(l, m)] += 1
for l in range(1, n + 1):
    for m in range(1, n + 1):
        counter += gcd(l, m) * list[l]

print(counter)

Solution (Python):
import math

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