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
k_ = int(input())
ans = 0


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


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

print(ans)

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

def gcds(x,y,z):
    n1 = math.gcd(x,y)
    n2= math.gcd(n1,z)
    return n2
total =0
for i in range(1,k+1):
    for j in range(1,k+1):
        if math.gcd(i,j) == 1:
            total += k
        else:
            for t in range(1,k+1):
                total += gcds(i,j,t)
print(total)

Solution (Python):
import collections

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

k=int(input())
cnt=collections.defaultdict(int)
for i in range(1,k+1): 
 for j in range(1,k+1):
   cnt[gcd(i,j)]+=1
ans=0
for i in range(1,k+1): 
 for key in cnt.keys():
   ans+=gcd(i,key)*cnt[key]
print(ans)

Solution (Python):
k = int(input())
import math
from functools import reduce
total = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            total += reduce(math.gcd,(i,j,l))

print(total)

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

Solution (Python):
import math
from itertools import product


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def sums(a, N):
    ans = ((N//a)*((N//a)+1)//2)*a
    return ans


def solve():
    K = read_int()
    return sum(math.gcd(math.gcd(a, b), c)
               for a, b, c in product(range(1, K+1), range(1, K+1), range(1, K+1)))


if __name__ == '__main__':
    print(solve())

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

Solution (Python):


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

Solution (Python):
import math

N = int(input())

ans = 0

for i in range(1, N + 1):
    for j in range(1, N + 1):
        ij = math.gcd(i, j)
        for k in range(1, N + 1):
            ans += math.gcd(ij, k)
print(ans)

Solution (Python):
import math

K = int(input())
ans = 0

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

print(ans)

Solution (Python):

import math
 
K = int(input())
ans_list = []
ans = 0
for a in range(1, K+1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            ans_list = [a, b, c]
            gcd_ans = ans_list[0]
            for item in ans_list:
                gcd_ans = math.gcd(gcd_ans, item)
            ans += gcd_ans
print(ans)

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

import math

def max_min(a,b):
    f = math.gcd(a,b)
    
    return f

ans = 0

for a in range(1, k + 1):
    for b in range(1, k + 1):
        
        n = max_min(a, b)
        
        if n == 1:
            ans += k
            
        else:
            for c in range(1, k + 1):
                
                ans += max_min(n, c)

print(ans)

Solution (Python):
def solve(k):
  def gcd(a, b):
    if a < b:
      a,b = b,a
    while b:
      a, b = b, a%b
    return a

  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

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('csolve', 'i8(i8)')(solve)
    cc.compile()

if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import csolve
    print(csolve(int(input())))

Solution (Python):
def solve(k):
  def gcd(a, b):
    if a < b:
      a,b = b,a
    while b:
      a, b = b, a%b
    return a

  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

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', 'i8(i8)')(solve)
    cc.compile()

if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import solve
    print(solve(int(input())))

Solution (Python):
import numba

@numba.njit(numba.i8(numba.i8), cache=True)
def solve(k):
  def gcd(a, b):
    if a < b:
      a,b = b,a
    while b:
      a, b = b, a%b
    return a

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

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

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

print(sum)

Solution (Python):
import math

k = int(input())

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

Solution (Python):
import sys
import math
import itertools
K = int(sys.stdin.readline())
ans = 0
for a, b, c in itertools.product(range(1, K+1),range(1, K+1),range(1, K+1)):
    ans += math.gcd(a, math.gcd(b, c))
print(ans)

Solution (Python):
import math

k = int(input())

box = [0]*(k+1)
ans = 0

for a in range(1,k+1):
    for b in range(1,k+1):
        box[math.gcd(a,b)] += 1

for i in range(1,k+1):
    for c in range(1,k+1):
        ans += math.gcd(i,c)*box[i]

print(ans)

Solution (Python):
import math

k = int(input())

box = [0]*(k+1)
ans = 0

for a in range(1,k+1):
    for b in range(1,k+1):
        box[math.gcd(a,b)] += 1

for a in range(1,k+1):
    for c in range(1,k+1):
        ans += math.gcd(a,c)*box[a]

print(ans)

Solution (Python):
import math
from functools import reduce


def gcd(*numbers):
    return reduce(my_gcd, numbers)


def my_gcd(i, j):
    if i > j:
        a = i
        b = j
    elif i == j:
        return i
    else:
        a = j
        b = i
    r = a % b

    if r == 0:
        return b
    return my_gcd(b, r)


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

print(sum)

Solution (Python):
from math import gcd

n=int(input())

s = 0

for i in range(1,n+1):
  if i == 1:
    s += n**2
  else:
    for j in range(1,n+1):
      g = gcd(i, j)
      if g == 1:
        s += n
      else:
        for k in range(1,n+1):
          s += gcd(g, k)
print(s)

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

print(sum)

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

sum = 0
gcd_a_b = 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
K = int(input())
result = 0
sum = 0

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

print(sum)

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop
from math import gcd

INF = float('inf')
NIL = - 1


K = int(input())

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

print(total)

Solution (Python):
import math
from functools import reduce

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

def myfunc(K):
    if K == 1:
        return 1
    elif K == 2:
        return 9

    temp = K
    for a in range(2,K):
        temp += sum([gcd(K,a,b) for b in range(1,a)])*6
    temp += sum([gcd(K,a,a) for a in range(1,K)])*6

    return myfunc(K-1) + temp

K = int(input())

print(myfunc(K))

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



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

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

for i in range(1,k+1):
    for ii in range(1,k+1):
        value = math.gcd(i,ii)
        for iii in range(1,k+1):
            sum += math.gcd(value,iii)
print(sum)

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

import functools

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
def gcd(nums):
    return functools.reduce(euclid, nums)

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

solution(K)

Solution (Python):
def main():
    k = int(input())
    res = 0
    for x in range(1, k + 1):
        for y in range(1, x + 1):
            for z in range(1, y + 1):
                d = gcd(y, z)
                ins = gcd(x, d)
                if x != y and y != z:
                    res += 6 * ins
                elif x == z:
                    res += ins
                else:
                    res += 3 * ins
    print(res)

def gcd(s, t):
    u = s % t
    if u == 0:
        return t
    return gcd(t, u)


    print(res)

if __name__ == "__main__":
    main()

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

print(sum)

Solution (Python):
K = int(input())
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
sum=0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            sum += gcd(gcd(i,j),k)

print(sum)

Solution (Python):
from math import gcd

k = int(input())

sum = 0
for i in range(k):
    for j in range(k):
        tmp = gcd(i+1, j+1)
        if tmp == 1:
            sum += k
        else :
            for l in range(k):
                sum += gcd(l+1, tmp)

print(sum)

Solution (Python):
import fractions

k = int(input())

ans = 0
gcd_table = [[0 for _ in range(k)] for _ in range(k)]
for i in range(k):
    for j in range(k):
        gcd_table[i][j] = fractions.gcd(i+1, j+1)
for i in range(k):
    for j in range(k):
        for l in range(k):
            ans += gcd_table[gcd_table[i][j]-1][l]
print(ans)

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

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

Solution (Python):
import math
from functools import reduce
a=1;b=1;c=1;d=0
n=int(input());
for i1 in range(n):
	for i2 in range(n):
		for i3 in range(n):
			d+=reduce(math.gcd,(a,b,c))
			c+=1
		b+=1;c=1;i3=0 
	a+=1;b=1;i2=0 
print(d)

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

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

print(ans)

Solution (Python):
import math
A = int(input())
def gcd(A):
    total = 0
    for i in range(1,A+1):
        for j in range(1,A+1):
            B = math.gcd(i,j)
            for k in range(1,A+1):
                total += math.gcd(B,k)
    return total
print(gcd(A))

Solution (Python):
def gcd(x,y):
    if x==y:
        return x
    elif x>y:
        r=-1
        while r!=0:
            r=x%y
            x=y
            y=r
        return x
    else:
        r=-1
        while r!=0:
            r=y%x
            y=x
            x=r
        return y

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

print(ans)

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

Solution (Python):
import math

def resolve():
    k=int(input())
    ans=0
    a=0
    b=0
    for h in range(1,k+1):
        for i in range(1,k+1):
            for j in range(1,k+1):
                 a=math.gcd(h,i)
                 b=math.gcd(i,j)
                 ans+=math.gcd(a,b)
    print(ans)
if __name__ == "__main__":
    resolve()

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

ans = 0
ab = []
for b in range(1, K+1):
    for a in range(1, K+1):
        ab.append(math.gcd(a, b))
        
for c in range(1, K+1):
    for i in ab:
        ans += math.gcd(c, i)
print(ans)

Solution (Python):
import math
def gud(a,b):
  if a%b==0:
    return b
  else:
    return gud(b,a%b)
a=int(input())
ans=0
for i in range(1,a+1):
  for j in range(1,a+1):
    n=math.gcd(i,j)
    for k in range(1,a+1):
      ans+=math.gcd(n,k)
print(ans)

Solution (Python):
import math

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

print(sum)

Solution (Python):

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


K = int(input())
SUM = 0
for a in range(K):
    a += 1
    for b in range(K):
        b += 1
        for c in range(K):
            c += 1
            NUMS = [a,b,c]
            SUM += euclid(euclid(a,b),c)
            
print("{}".format(SUM))

Solution (Python):
K = int(input())
import math
sumnation = 0
gcdlist = []
for A in range(1,K+1):
    for B in range(1,K+1):
        gcdlist.append(math.gcd(A,B))
for a in range(1,1+K):
    for b in range(1,1+K):
        gcd_a_b = gcdlist[(a-1)*K+b-1]
        for c in range(1,1+K):
            sumnation += gcdlist[(gcd_a_b-1)*K+c-1]
print(sumnation)

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

Solution (Python):
import math
from functools import reduce

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

def myfunc(K):
    if K == 1:
        return 1
    elif K == 2:
        return 9

    temp = K
    for a in range(2,K):
        temp += sum([gcd(K,a,b) for b in range(1,a)])*6
    temp += sum([gcd(K,a,a) for a in range(1,K)])*6

    return myfunc(K-1) + temp           

K = int(input())

print(myfunc(K))

Solution (Python):
n = int(input())
import numpy as np
total = np.gcd.outer(np.arange(1,n+1), np.gcd.outer(np.arange(1,n+1), np.arange(1, n+1)).flatten())
print(np.sum(total))

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

print(ans)

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

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

def gcd3(x, y, z):
    return gcd2(gcd2(x, y), z)

def pat(x, y, z):
    p = len(set([x, y, z]))
    if p == 1:
        return 1
    elif p == 2:
        return 3
    else:
        return 6

K = int(input())
S = 0
for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            S += gcd3(i, j, k) * pat(i, j, k)
print(S)

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

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

Solution (Python):
from math import gcd

K = int(input())
ans = 0 

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

Solution (Python):
from math import gcd

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

Solution (Python):
def gcd(a, b):
  if a < b:
    a_init = a
    a = b
    b = a_init
  while b != 0:
    r = a % b
    a = b
    b = r
  return a
	
K = int(input())
count = 0
temp = []
for a in range(1, K+1):
	for b in range(1, a):
		temp.append(gcd(a, b))
for c in range(1, K+1):
	for j in range(len(temp)):
		count += gcd(c, temp[j]) * 2
	for k in range(1, K+1):
		count += gcd(c, k)
print(count)

Solution (Python):
from math import gcd

def threegcd(a, b, c):
    return gcd(gcd(a,b), c)

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 += threegcd(i, j, k)

print(ans)

Solution (Python):
K = int(input())
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        r = a%b
        a = b
        b = r
    return a
count = 0
temp = list()
for n in range(1, K+1):
    for m in range(1, n):
        temp.append(gcd(n, m))
for l in range(1, K+1):
    for j in range(len(temp)):
        p = gcd(l, temp[j])
        count += 2 * p
    for k in range(1, K+1):
        q = gcd(l, k)
        count += q
print(count)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from functools import reduce
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; cnt = 0; ansli = []; tmpli = []; candili = []; stillset = set()
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]
def mi(n): return [wi() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

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

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

K = i()

sigma = 0
nums = [i for i in range(1, K + 1)]
for abc in itertools.combinations_with_replacement(nums, 3):  
    tmp = gcd_list(abc)
    abc_set = set(abc)
    sigma += int(tmp * (6 / (math.factorial(-len(abc_set) + 4))))

print(sigma)

"""
[1, 2, 3]
(1, 1)
(1, 2)
(1, 3)
(2, 2)
(2, 3)
(3, 3)
"""

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

print(ans)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from functools import reduce
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; cnt = 0; ansli = []; tmpli = []; candili = []; stillset = set()
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]
def mi(n): return [wi() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

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

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

K = i()

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

print(sigma)

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

Solution (Python):
import math

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

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

count = 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):
            count += math.gcd(tmp, k)

print(count)

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

Solution (Python):
from math import *

K = int(input())

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

print(sum)

Solution (Python):
import math
K=int(input())
dp=[[0][0]]*K
sum_gcd=0
c=1
for a in range(1,K+1):
    for b in  range(1,K+1):
            for c in  range(1,K+1):
                sum_gcd+=math.gcd(c,math.gcd(a,b))
print(sum_gcd)

Solution (Python):
from collections import deque
from functools import reduce
import math; floor,ceil = math.floor,math.ceil
import sys; input = lambda: sys.stdin.readline().rstrip()
aint = lambda: int(input()); ints = lambda: list(map(int, input().split()))
Yes = lambda boolean: print('Yes') if boolean else print('No')
YES = lambda boolean: print('YES') if boolean else print('NO')
is_even = lambda x: True if x%2==0 else False
s = lambda x: int(x*(x+1)*0.5)

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

def main():
    n = aint()
    ans = 0
    for a in range(n):
      for b in range(a,n):
        for c in range(b,n):
          if (a==b and b==c):
            ans += gcd(a+1,b+1,c+1)
          elif (a==b or b==c or c==a):
            ans += gcd(a+1,b+1,c+1)*3
          else:
            ans += gcd(a+1,b+1,c+1)*6
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from math import gcd
K = int(input())
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 and j==k:
                Sum += i
            elif i!=j and j!=k and k!=i:
                Sum += gcd(i,gcd(j,k))*6
            else:
                Sum += gcd(i,gcd(j,k))*3
                
print(Sum)

Solution (Python):
import math

k = int(input())
a = []
result = []

for i in range(1,k+1):
    for j in range(1,k+1):
        a.append(math.gcd(i,j))

for i in range(1,k+1):
    result.extend(math.gcd(n,i) for n in a)

print(sum(result))

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

print(A)

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

Solution (Python):
import math

K = int(input())

gcd2 = [[0 for i in range(K)] for i in range(K)]

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

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


def main():
    input = sys.stdin.readline
    K = int(input())
    assert 1 <= K <= 200
    total = 0
    for i in range(1, K+1):
        for j in range(1, K+1):
            a = euclidean_algorithm(i, j)
            for k in range(1, K+1):
                total += euclidean_algorithm(a, k)
    print(total)


def euclidean_algorithm(a, b):
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b
    return b


if __name__ == "__main__":
    main()

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


def main():
    input = sys.stdin.readline
    K = int(input())
    assert 1 <= K <= 200
    total = 0
    for i in range(1, K+1):
        for j in range(1, K+1):
            a = euclidean_algorithm(i, j)
            for k in range(1, K+1):
                total += euclidean_algorithm(a, k)
    print(total)


def gcd_list(numbers):
    return reduce(euclidean_algorithm, numbers)


def euclidean_algorithm(a, b):
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b
    return b


if __name__ == "__main__":
    main()

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

ans = 0
a = 0

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

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

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

Solution (Python):

import math
K=int(input())

tot=0





ls=[0]*202
for i in range(1,K+1):
    for j in range(1,K+1):
        tmp=math.gcd(i,j)
        ls[tmp+1]+=1
tot=0
for i in range(1,K+1):
    for j in range(1,201):
        tot+=ls[j+1]*math.gcd(j,i)

print(tot)

Solution (Python):
import math
from functools import reduce

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

count = 0
n = int(input())
for i in range(1, n+1):
    for j in range(i, n+1):
        for k in range(j, n+1):
            if i==j==k:
                count += gcd(i, j, k)
            elif i==j or j==k:
                count += 3*gcd(i, j, k)
            else:
                count += 6*gcd(i, j, k)

print(count)

Solution (Python):
import math
from functools import reduce

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


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

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

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

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

Solution (Python):
import math
from functools import reduce

K = int(input())

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

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

Solution (Python):


import math

ar = [[0]*201 for i in range(201)]
for i in range(1, 201, 1):
	for j in range(1, 201, 1):
		ar[i][j] = math.gcd(i, j)
		
n, ans = int(input()), 0
for i in range(1, n+1, 1):
	for j in range(1, n+1, 1):
		for k in range(1, n+1, 1):
			ans += ar[ar[i][j]][k]
print(ans)