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())
tanget_num = range(1, K+1)
sum_  = sum([math.gcd(i, math.gcd(j, k)) for i in tanget_num for j in tanget_num for k in tanget_num])

print(str(sum_))

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

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

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

Solution (Python):

K = int(input())


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
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:
                dup_num = 1
            elif i == j or j == k:
                dup_num = 3
            else:
                dup_num = 6
            ans += gcd(gcd(i, j), k) * dup_num

print(ans)

Solution (Python):
import math

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

K = int(input())

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

print(ans)

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



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

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

Solution (Python):
a=int(input())
b=0
c=1
import math
from functools import reduce

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

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

for i in range(1,a+1):
    for j in range(1,a+1):
        
        for z in range(1,a+1):
            

            b+=gcd(i,j,z)


print(b)

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

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 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):
            x = math.gcd(i,j)
            y = math.gcd(j,k)
            ans += math.gcd(x,y)
print(ans)

Solution (Python):
from math import gcd

N = int(input())

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

print(sum)

Solution (Python):
import math
n=int(input())
g=0
for i in range(1,1+n):
    for j in range(1,1+n):
        d=math.gcd(i,j)
        for z in range(1,n+1):
            f=math.gcd(z,d)
            g+=f
print(g)

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

memo = [[None] * (K + 1) for _ in range(K + 1)]

def mygcd(a, b):
    if memo[a][b] != None: return memo[a][b]
    else:
        if a < b:
            ret = mygcd(b, a)
        elif b == 0:
            ret = a
        else:
            ret = mygcd(b, a % b)
        
        memo[a][b] = ret
        memo[b][a] = ret
        return ret

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

Solution (Python):
from collections import defaultdict
import math

N = int(input())
wa = 0
d = defaultdict(set)
d[1].add(1)

for i in range(2, 201):
    for j in range(i, 0, -1):
        if i % j == 0:
            d[i].add(j)

for i in range(1, N+1):
    for j in range(1, N+1):
        for k in range(1, N+1):
            
            wa += max(d[i] & d[j] & d[k])
print(wa)

Solution (Python):
from math import gcd

s=int(input())
a=0

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

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

K = int(input())

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

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

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

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

def sgcd(i, j):
    if memo[i][j] == 0:
        memo[i][j] = math.gcd(i, j)
    return memo[i][j]

def main():
    N = int(input())
    ans = 0
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            a = sgcd(i, j)
            for k in range(1, N + 1):
                ans += sgcd(a, k)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import math
from itertools import combinations

def main():
    k = int(input())
    res = 0
    memo = [[0 for _ in range(k+1)] for _ in range(k+1)]
    for i in range(1, k+1):
        for j in range(i, k+1):
            tmp = math.gcd(i,j)
            memo[i][j] = tmp
            memo[j][i] = tmp

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

    for c in combinations(range(1,k+1),2):
        ab = memo[c[0]][c[1]]
        res += ab * 6

    for c in combinations(range(1,k+1), 3):
        ab = memo[c[0]][c[1]]
        abc = memo[ab][c[2]]
        res += abc * 6
    print(res)


if __name__ == '__main__':
    main()

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


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


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

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

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

kotae = 0
K = int(input())

X = []
for i in range(1,K+1):
    for k in range(1,K+1):
        z = gcd(i,k)
        for l in range(1,K+1):
            kotae += gcd(z,l)
            
print(kotae)

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

Solution (Python):
import math
from functools import reduce
import itertools
k=int(input())
def gcd(*numbers):
    return reduce(math.gcd,numbers)
ans=0
for i,j,m in itertools.product(range(1,k+1),range(1,k+1),range(1,k+1)):
    ans+=gcd(i,j,m)
print(ans)

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

Solution (Python):
import math
k = int(input())
ans = k**3 - (k-1)**3
for a in range(2,k+1):
  for b in range(2,k+1):
    tmp = math.gcd(a,b)
    for c in range(2,k+1):
      ans += math.gcd(tmp, c)
print(ans)

Solution (Python):
import math
from functools import reduce

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

def solution():
    k = int(input())
    nums = []
    for i in range(1, k+1):
        for j in range(1, k+1):
            for l in range(1, k+1):
                if i == j == l:
                    nums.append(i)
                else:
                    nums.append(gcd(i,j,l))
    print(sum(nums))

solution()

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

ans = 0

lst = [[0 for _ in range(1, k+1)] for __ in range(k+1)]
cnt = [0 for _ in range(1, k+1)]


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

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

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

Solution (Python):
k = int(input())
r = 0
def gcd(num1, num2):
	if num2 == 0:
		return num1
	return gcd(num2, num1 % num2)
for a in range(1, k+1):
	for b in range(1, k+1):
		for c in range(1, k+1):
			r += gcd(a, gcd(b, c))
print(r)

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

n=int(input())
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!=k:
				ans+=6*gcd(gcd(i,j),k)
			elif i==j==k:
				ans+=i
			else:
				ans+=3*gcd(gcd(i,j),k)
print(ans)

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

print(ans)

Solution (Python):
from math import gcd

K = int(input())

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

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

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

if __name__ == "__main__":
  main()

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

Solution (Python):
import math

K=int(input())
r=0

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

Solution (Python):
import math

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

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

print(ans)

Solution (Python):

import sys
import math

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

def gcd(x: int, y: int):
    """xとyの最大公約数を求める"""
    return gcd(y, x % y) if y else x
    

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

Solution (Python):
from math import gcd 
k = int(input())
sss = 0
for a in range(1,k+1):
    for b in range(a+1,k+1):
        tmp = gcd(a,b)
        sss += 6*tmp
        for c in range(b+1,k+1):
            sss += 6*gcd(tmp,c)
sss += k*(k+1)//2
print(sss)

Solution (Python):
import math

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

Solution (Python):
import math

number = int(input())
sumx = 0
N = number+1
for i in range(1,N):
  for j in range(1,N):
    for k in range(1,N):
      sumx = sumx + math.gcd(math.gcd(i,j), k)

print (sumx)

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

from math import gcd

y = 0
for i in range(1, n + 1):
    for j in range(1, n + 1):
        x = gcd(i, j)
        for k in range(1, n + 1):
            y += gcd(x, k)

print(y)

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

K = int(input())

def GCD(x):
    return reduce(math.gcd, x)

s = 0

for x in combinations_with_replacement(range(1, K + 1), 3):
    if x[0] == x[1] == x[2]:
        s += GCD(x)
    elif x[0] == x[1] or x[1] == x[2] or x[0] == x[2]:
        s += GCD(x) * 3
    else:
        s += GCD(x) * 6

print(s)

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

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


K = int(input())

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

Solution (Python):
from math import *

K = int(input())

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

print(ans)

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


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

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

ans = 0
for i in range(1,k+1):
    for j in range(1, k + 1):
        p = ansl[i][j]
        for k in range(1, k + 1):
            ans += ansl[p][k]

print(ans)

Solution (Python):
import math
from functools import reduce
 
n = int(input())
answer = 0
 
def gcd(*numbers):
    return reduce(math.gcd,numbers)
 
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):
def euc(i, j):
    if i > j:
        i, j = j, i
    while j%i != 0:
        k = j - i
        if k > i:
            i, k = k, i
        j = i%k
        if j == 0:
            return(k)
        i = k
        if i > j:
            i, j = j, i
    return i


N = int(input())
sum = 0
for i in range(1, N + 1):
    for j in range(1, N + 1): 
        ij = euc(i, j)
        for k in range(1, N + 1):
            sum += euc(ij, k)
print(sum)

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

Solution (Python):
import math
import itertools

k = int(input())
result = 0

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

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

print(result)

Solution (Python):
from math import gcd
def solve():
    K = int(input())

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

if __name__ == '__main__':
    solve()

Solution (Python):
import math

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

Solution (Python):
from math import gcd

K = int(input())
sum = 0

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

print(sum)

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


K = int(input())

ans = 0

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

print(ans)

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

k = int(input())

result = []

for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            result.append(calc_saidaikouyaku(a, calc_saidaikouyaku(b, c)))

print(sum(result))

Solution (Python):
import math

k = int(input())
k_arr = range(1,k+1)

a_arr = list()
b_arr = list()

for k in k_arr:
    for a in k_arr:
        a_arr.append(a)

for b in k_arr:
    for k in k_arr:
        b_arr.append(b)

gcds = list(map(math.gcd,a_arr,b_arr))

total = 0
for c in k_arr:
    c_arr = [c] * k * k
    total += sum(map(math.gcd,gcds,c_arr))

print(total)

Solution (Python):
K = int(input())
 
from itertools import product
kumi = product(range(1, K+1), repeat=3)
 
from math import gcd
 
memo = [[None for i in range(K+1)] for i in range(K+1)]

 
ans = 0
for a, b, c in kumi:
    a, b, c = sorted([a, b, c])
    if memo[a][b] is not None:
        v = memo[a][b]
    else:
        v = gcd(a, b)
        memo[a][b] = v
        memo[b][a] = v
    d = gcd(v, c)
    ans += d
 
print(ans)

Solution (Python):
import itertools
import math
from functools import reduce
K=int(input())
ans=0
for i in range(1,K+1):
  for j in range(1,K+1):
    t=math.gcd(i,j)
    for k in range(1,K+1):
      ans+=math.gcd(t,k)
print(ans)

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

Solution (Python):
import math
from functools import reduce
s=0
K=int(input())+1
for a in range(1,K):
    for b in range(a,K):
        for c in range(b,K):
            if a==b==c:
                s+=a
                continue
            x=reduce(math.gcd,(a,b,c))
            if a==b or b==c or c==a:
                s+=x*3
            else:
                s+=x*6
print(s)

Solution (Python):
import numpy as np

K = int(input())
x = np.arange(1, K + 1)
nums = np.gcd.outer(np.gcd.outer(x, x), x)

print(np.sum(nums))

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

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

from math import gcd

y = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        x = gcd(i, j)
        for k in range(1, n+1):
            y += gcd(x,k)

print(y)

Solution (Python):
import math

K = int(input())

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

print(ans)

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

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

Solution (Python):
from math import gcd
from functools import reduce
def gcd_list(numbers):
   return reduce(gcd, numbers)
k=int(input())
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for x in range(1,k+1):
            ans+=gcd_list([i,j,x])
print(ans)

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

import math
from functools import reduce

sum = 3*(K-1)*(K-1) + 3*(K-1) + 1

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

print(sum)

Solution (Python):
from math import gcd
K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(i,K+1):
        temp = gcd(i,j)
        for k in range(j,K+1):
            if i==j==k:
                ans+=gcd(temp, k)
            elif len({i,j,k}) == 2:
                ans+=gcd(temp, k)*3
            else:
                ans+=gcd(temp, k)*6
print(ans)

Solution (Python):
import math
def GCD(a,N):
    gcd = a[0]
    for i in range(1, N):
        gcd = math.gcd(gcd, a[i])
    return gcd


k = int(input())


ans = 0
L = []
for i in range(1, k+1):
    for j in range(1, k+1):
        for l in range(1, k+1):
            if i==1 or j==1 or l==1:
                ans += 1
            else:
                ans += GCD([i,j,l], 3)

print(ans)

Solution (Python):
from math import gcd

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

print(res)

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

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

def gcd_3(a,b,c):
    g = gcd(a,b)
    g = gcd(g,c)
    return g

sm = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            sm += gcd_3(a,b,c)

print(sm)

Solution (Python):
import math
k=int(input())
sum=k*(k+1)/2
for i in range(1,k+1):
    for j in range(i+1,k+1):
        m=math.gcd(i,j)
        sum+=6*m*(k-j+1)
        for l in range(j+1,k+1):
            n=math.gcd(m,l)
            if n==m:
                continue
            else:
                sum-=6*m-6*n
print(int(sum))

Solution (Python):
import math

K = int(input())
ans = 0

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

print(ans)

Solution (Python):
from math import gcd

k = int(input())

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

print(ans)

Solution (Python):
import math

K = int(input())
sum = 0

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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import gcd, ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()

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)


exit()
q = [[str(i)] for i in range(1, K+1)]

s = []
ans = 0
while q:
    a = q.pop()
    
    if len(a) == 3:
        
        ans += int(a[-1])
        
    else:
        for i in range(1, K+1):
            b = deepcopy(a)
            if int(b[-1]) <= i:
                b.append(b[-1])
            
            else:
                b.append(str(i))
            q.append(b)
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 m in range (1,k+1):
            ans += math.gcd(tmp,m)

print(ans)

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

print(ans)

Solution (Python):
from math import gcd








k = int(input())

ans = 0
L = []
G = [0] * k**3

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

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols
    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])
    return ret


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_map_as_int(H):
    '''
    
    '''
    ret = []
    for _ in range(H):
        ret.append([1 if s == '
        
        
    return ret


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations, combinations_with_replacement
from bisect import bisect_left, bisect_right  
from math import gcd


def lcm(a, b):
    
    g = gcd(a, b)
    return a * b // g





def f(K):
    nums = list(range(1, K + 1))
    ans = 0
    for a, b, c in product(nums, nums, nums):
        ans += gcd(gcd(a, b), c)
    return ans


print(f(int(input())))

Solution (Python):
import itertools
import math
 
K = int(input())
l = range(1, K+1)
ans = sum(l)
 
for a, b in itertools.combinations(l, 2):
    ans += math.gcd(a, b) * 6
 
for a, b, c in itertools.combinations(l, 3):
    ans += math.gcd(math.gcd(a,b), c)*6
    
        
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) :
        tmp = math.gcd(a, b)
        for c in range(1 , K+1) :
            sum = sum + math.gcd(tmp, c)

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

print(ans)

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

Solution (Python):
import math
def getInput():
    return [int(i) for i in input().rstrip().split(' ')]


N = getInput()[0]
sums = 0
for i in range(1, N+1):
    for j in range(1, N+1):
        n = math.gcd(i, j)
        for k in range(1, N+1):
            sums += math.gcd(n, k)

print(sums)

Solution (Python):
from math import gcd

k = int(input())
tot = 0

for l in range(1, k + 1):
    for m in range(1, k + 1):
        for n in range(1, k + 1):
            tot += gcd(gcd(l, m), n)
print(tot)

Solution (Python):
import math

l = int(input())
s = 0

for i in range(1, l+1):
  for j in range(1, l+1):
    tmp = math.gcd(i,j)
    for j in range(1, l+1):
      s += math.gcd(tmp,j)
  
print(s)

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

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

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

sum = 0
for a in range(1,k):
  for b in range(a,k):
    for c in range(b,k):
      t = len(set([a,b,c]))
      if t==1:
        sum+= reduce(math.gcd, [a,b,c])
      elif t==2:
        sum+= 3*reduce(math.gcd, [a,b,c])
      else:
        sum+= 6*reduce(math.gcd, [a,b,c])

print(sum)

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

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

print(ans)

Solution (Python):
import math
from functools import reduce
from itertools import *
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
 
K = int(input())
ans = 0
for i in product([i for i in range(1,K+1)], repeat = 3):
  ans += gcd(i[0],i[1],i[2])
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):
        x = math.gcd(i, j)
        for k in range(1, K+1):
            ans += math.gcd(x, k)

print(ans)