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):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False


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


def main():
    K = I()
    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__':
    main()

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()

nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False


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


def main():
    K = I()
    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__':
    main()

Solution (Python):
import math, itertools


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


k = int(input())
print(
    sum(
        g(a, b, c)
        for a, b, c in itertools.product(range(1, k + 1), repeat=3)))

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

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

print(ans)

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

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

print(ans)

Solution (Python):
import itertools
import math
import fractions
import functools
k = int(input())



sum = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        gcd1 = math.gcd(i, j)
        for l in range(1,k+1):
            sum += math.gcd(gcd1,l)

print(sum)

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

K = int(input())
 
res = 0
for i in range(1, K+1):
  for j in range(1, K+1):
    gcd1 = math.gcd(i, j)
    for k in range(1, K+1):
      if gcd1 == 1:
        res += 1
      else:
        res += math.gcd(gcd1, k)
print(res)

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

import math
for i1 in range(k):
    for i2 in range(k):
        for i3 in range(k):
            ans+=math.gcd(math.gcd(i1+1,i2+1),i3+1)
    
print(ans)

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

res = 0
for i in range(1, K+1):
  for j in range(1, K+1):
    gcd1 = math.gcd(i, j)
    for k in range(1, K+1):
      if gcd1 == 1:
        res += 1
      else:
        res += math.gcd(gcd1, k)
print(res)

Solution (Python):
import math

K = int(input())

r = 0

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

print(r)

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

Solution (Python):
import itertools
import math
ans = 0
for a,b,c in itertools.combinations_with_replacement(range(1,int(input())+1),3):
    G = math.gcd(a,math.gcd(b,c))
    if a==b==c:
        ans += G
    elif a==b or b==c:
        ans += 3*G
    else:
        ans += 6*G
    
print(ans)

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

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

Solution (Python):
import math

K = int(input())

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

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


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

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

print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    import math
    k=int(input())
    answer=0
    l=list(range(1,k+1))
    for x in range(1,k+1):
        for y in range(1,k+1):
            for z in range(1,k+1):
                answer+=math.gcd(math.gcd(x,y),z)
    print(answer)
resolve()

Solution (Python):

from math import gcd
K = int(input()) +1
rt = 0
for x in range(1, K):
    for y in range(1, K):
        for z in range(1, K):
            rt += gcd(gcd(x,y), z)
print(rt)

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

map_list = [[0 for i in range(k+1)]for j in range(k+1)]
for i in range(1,k+1):
    for j in range(1,k+1):
        map_list[i][j]=math.gcd(i,j)

ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        gcd1 = map_list[i][j]
        for k in range(1,k+1):
            ans+=map_list[k][gcd1]
print(ans)

Solution (Python):
from math import gcd

def solve():
    K = int(input())+1
    ans = 0
    for i in range(1,K):
        for j in range(1,K):
            for k in range(1,K):
                ans += gcd(gcd(i, j),k)
    return ans

print(solve())

Solution (Python):
from math import gcd

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

Solution (Python):
import math
K=int(input())
def gcd(a,b,c):
    s=math.gcd(a,b)
    s=math.gcd(s,c)
    return s
t=0
for a in range(K):
    for b in range(K):
        s=math.gcd(a+1,b+1)
        for c in range(K):
            t+=math.gcd(c+1,s)
print(t)

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

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

print(c)

Solution (Python):
import math
from functools import reduce

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

print(sum)

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

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

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

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

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


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


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

print(ans)

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

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

ans = 0
for x in range(1,N+1):
  for y in range(1,N+1):
    for z in range(1,N+1):
      ans += gcd(gcd(x, y), z)
print(ans)

Solution (Python):



import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf


from functools import lru_cache

import math

import bisect

def mutual_division_method(a, b):
    while not (a == 0 or b == 0):
        if a < b:
            b = b % a
        else:
            a = a % b
    if a == 0:
        return b
    else:
        return a



def gcd(a, b, c):
    
    d = mutual_division_method(a, b)
    e = mutual_division_method(d, c)
    
    return e

if __name__ == '__main__':
    k = int(input())
    s = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                ans = gcd(a, b, c)
                s += ans
    
    print(s)

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

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

Solution (Python):
from math import gcd
K = int(input())
m = 0
for i in range(1, K+1):
  for j in range(1, K+1):
    w = gcd(i, j)
    if w==1:
      m += K
    else:
      for k in range(1, K+1):
        m += gcd(w, k)
print(m)

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

Solution (Python):
K = int(input())
from math import gcd 
ans=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:
        ans += gcd(gcd(a,b),c)
      elif a==b or b==c or c==a:
        ans += gcd(gcd(a,b),c)*3
      else:
        ans += gcd(gcd(a,b),c)*6
      
print(ans)

Solution (Python):
from sys import stdin
from itertools import product

def gcd(a, b):
    while a > 0 and b > 0:
        if a >= b:
            a %= b
        else:
            b %= a
    return max(a, b)

k = int(stdin.readline())
ls = [[0 for j in range(k+1)] for i in range(k+1)]
for i in range(1, k+1):
    for j in range(i, k+1):
        res = gcd(i, j)
        ls[i][j] = res
        ls[j][i] = res
_sum = 0
for i in product(range(1,1+k), repeat=3):
    _sum += ls[ls[i[0]][i[1]]][i[2]]
print(_sum)

Solution (Python):
def gcd(a,b):
    if a>b:
        r=a%b
        if r==0:
            return b
        return gcd(b,r)
    elif a<b:
        r=b%a
        if r==0:
            return a
        return gcd(a,b%a)
    else:
        return a
k=int(input())
sum=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            sum+=gcd(i,gcd(j,l))
print(sum)

Solution (Python):
from math import gcd as 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(j, k), i)

print(ans)

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

Solution (Python):
from math import gcd

def gcd_3(a, b, c):
    return gcd(gcd(a, b), c)
sum_gcd = 0
K = int(input())
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for l in range(1, K + 1):
            sum_gcd += gcd_3(i, j, l)

print(sum_gcd)

Solution (Python):
from math import gcd

def solve():
    K = int(input())
    ans = 0

    for i in range(1,K+1):
        for k in range(1,K+1):
            b = gcd(i, k)
            for m in range(1,K+1):
                ans += gcd(b, m)
    return ans

print(solve())

Solution (Python):
from math import gcd


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

print(c)

Solution (Python):
from math import gcd

K = int(input())
ans = 0

for i in range(1,K+1):
    for k in range(1,K+1):
        b = gcd(i, k)
        for m in range(1,K+1):
            ans += gcd(b, m)

print(ans)

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

ans=0

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

print(ans)

Solution (Python):
import math
k = int(input())
b = 3*k*k - 3*k + 1
for i in range(2,k+1):
    for j in range(2,k+1):
        ij = math.gcd(i,j)
        for m in range(2,k+1):
            b += math.gcd(ij,m)
print(b)

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

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

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

Solution (Python):
import math

K = int(input())

total = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        ab = math.gcd(a, b)
        if ab == 1:
            total += K
        else:
            for c in range(1, K + 1):
                total += math.gcd(ab, c)

print(total)

Solution (Python):
import math

K = int(input())

total = 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):
            total += math.gcd(ab, c)

print(total)

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

Solution (Python):
import math
K = int(input())
ans = 0
d = [[math.gcd(i, j) for i in range(0, K+1)] for j in range(0, K+1)]

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

Solution (Python):
import math
from functools import reduce



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

Solution (Python):
from math import gcd
counter = 0
K = int(input())
for a in range(1,K+1):
    for b in range(1,K+1):
        if gcd(a,b)==1:
            counter += K
        else:
            for c in range(1,K+1):
                d = gcd(a,b)
                counter += gcd(c,d)


print(counter)

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


print(counter)

Solution (Python):
from math import gcd
k = int(input())
sum = 0
lst = []
for a in range(1,k+1):
  for b in range(1,k+1):
      g = gcd(a,b)
      lst.append(g)
for c in range(1,k+1):
    for i in range(len(lst)):
        sum += gcd(lst[i],c)     
print(sum)

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

Ans=0
from math import gcd
for i in range(K):
    for j in range(K):
        tempA=gcd(i+1,j+1)
        for k in range(K):
            Ans+=gcd(tempA,k+1)
            
print(Ans)

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

Ans=0
from math import gcd
for i in range(K-1):
    for j in range(K-1):
        tempA=gcd(i+1,j+1)
        for k in range(1,K):
            Ans+=gcd(tempA,k)
            
print(Ans)

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

Ans=0
from math import gcd
for i in range(1,K):
    for j in range(1,K):
        tempA=gcd(i,j)
        for k in range(K-1):
            Ans+=gcd(tempA,k+1)
            
print(Ans)

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

Ans=0
from math import gcd
for i in range(1,K):
    for j in range(1,K):
        tempA=gcd(i,j)
        for k in range(1,K):
            Ans+=gcd(tempA,k)
            
print(Ans)

Solution (Python):
def gcd(a,b):
    if a < b:
        a, b = b, a
    if mem[a][b]:
        return mem[a][b]
    if b == 0:
        return a
    mem[a][b] = gcd(b, a % b)
    return mem[a][b]

k = int(input())
ans = 0
mem = [[0 for a in range(k+1)]for b in range(k+1)]
n = k+1
for i in range(1,n):
    for j in range(1,n):
        d = gcd(i,j)
        for k in range(1,n):
            ans += gcd(d,k)
print(ans)

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

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

s = 0

for a in range(1, k + 1):
    
    s += a 
    for b in range(a + 1, k + 1):
        if a == b:
            print(a, b)
            continue
        
        s += 6 * gcd(a, b)
        for c in range(b + 1, k + 1):
            if a == c or b == c:
                print(a, b, c)
                continue
            
            s += 6 *  gcd(a, gcd(b, c)) 
        
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):
        d = gcd(a, b)
        for c in range(1, k+1):
            ans += gcd(d, c)
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):
    x=math.gcd(i, j)
    for k in range(1, K+1):
      _gcd=math.gcd(x, k)
      count += _gcd
print(count)

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

Solution (Python):
from collections import defaultdict

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

gcd_cnt = defaultdict(int)
ans = 0
k = int(input())
for a in range(1, k+1):
    for b in range(1, k+1):
        gcd_cnt[gcd(a, b)] += 1

for key in gcd_cnt:
    for c in range(1, k+1):
        ans += gcd(c, key) * gcd_cnt[key]
print(ans)

Solution (Python):
import math
from functools import reduce

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

comb_count = {1:1, 2:3, 3:6}
k = int(input())
ans = 0
for a in range(1, k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            ans += gcd(a, b, c) * comb_count[len(set([a, b, c]))]
print(ans)

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

Solution (Python):


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


K = int(input())
G = [[0]*K for i in range(K)]
x=0
for i in range(K):
    for j in range(K):
        g1=gcd(i+1,j+1)
        G[i][j]=g1

for i in range(K):
    for j in range(K):
        for k in range(K):
            g1=G[i][j]

            x=x+G[g1-1][k]



            

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

Solution (Python):
import sys
import numpy as np
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

def main():
    K = int(input())
    num_list = np.array([i for i in range(1,K+1)])
    print(np.sum(np.gcd.outer(np.gcd.outer(num_list,num_list),num_list)))

main()

Solution (Python):
import itertools
import math
import sys
import numpy as np
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()


def main():
    K = int(input())
    num_list = np.array([i for i in range(1,K+1)])
    print(np.sum(np.gcd.outer(np.gcd.outer(num_list,num_list),num_list)))

main()

Solution (Python):
from math import gcd

def main():
    n = int(input())

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

    print(t)

if __name__ == "__main__":
    main()

Solution (Python):
def gcd(p, q) :
	if p % q == 0 :
		return q
	else :
		return gcd(q,p%q)
if __name__ == '__main__':
	k = int(input())
	a = []
	ans = 0
	for i in range(1,k+1) :
		for j in range(1,k+1) :
			a.append(gcd(i,j))
	for i in range(1,k+1) :
		for j in a :
			ans += gcd(i,j)
	print(ans)

Solution (Python):

from math import gcd
K = int(input())+1
Sum = 0
for i in range(1,K):
    for j in range(1,K):
        d = gcd(i,j)
        for k in range(1,K):
            Sum+=gcd(d,k)

print(Sum)

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

s = 0

for i1 in range(1, k+1):
    s = s + i1
    for i2 in range(1, i1):
        x1, x2 = i1, i2
        while x2 != 0:
            x1, x2 = x2, x1 % x2
        gcd1 = x1
        s = s + gcd1 * 6
        for i3 in range(i1+1, k+1):
            x1, x2 = gcd1, i3
            while x2 != 0:
                x1, x2 = x2, x1 % x2
            gcd2 = x1
            s = s + gcd2 * 6

print(s)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)

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

x = int(input())

ans=0

for a in range(1,x+1):
    for b in range(1,a+1):
        for c in range(1,b+1):
            gcd1=gcd(a,b)
            gcd2=gcd(gcd1,c)
            if a==b and b==c:
                ans += gcd2
            elif a==b or b==c or c==a:
                ans += 3*gcd2
            else:
                ans += 6*gcd2

print(ans)

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

s = 0
for i1 in range(1, k+1):
    for i2 in range(1, i1+1):
        x1, x2 = i1, i2
        while x2 != 0:
            x1, x2 = x2, x1 % x2
        gcd1 = x1
        s2 = i1 == i2
        for i3 in range(i1, k+1):
            x1, x2 = gcd1, i3
            while x2 != 0:
                x1, x2 = x2, x1 % x2
            gcd2 = x1

            s3 = i2 == i3 or i1 == i3
            if s2 and s3:
                s = s + gcd2
            elif s2 or s3:
                s = s + gcd2*3
            else:
                s = s + gcd2*6
print(s)

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

for i in range(1,K+1):
    for a in range(1,K+1):
        x = gcd(i,a) 
        for j in range(1,K+1):
            plus += gcd(x,j) 
            
print(plus)

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

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


@lru_cache(maxsize=None)
def _gcd(a, b):
    return math.gcd(a, b)


k = int(input())
C = combinations_with_replacement(range(1, k + 1), 3)

r = 0
for a, b, c in C:
    l = len({a, b, c})
    t = 1
    if l is 3:
        t = 6
    if l is 2:
        t = 3
    r += _gcd(_gcd(a, b), c) * t

print(r)

Solution (Python):


from math import gcd
K = int(input())+1
Sum = 0
for i in range(1,K):
    for j in range(1,K):
        d = gcd(i,j)
        for k in range(1,K):
            Sum+=gcd(d,k)

print(Sum)

Solution (Python):
from numba import njit
from sys import stdin


@njit(cache=True)
def gcd(x, y):
    if x % y == 0:
        return y
    return gcd(y, x % y)


@njit(cache=True)
def fact(x):
    if x == 1:
        return x
    return x * fact(x - 1)


def main():
    k = int(stdin.readline())

    ans = 0

    for a in range(1, k + 1):
        for b in range(a, k + 1):
            d = gcd(a, b)
            for c in range(b, k + 1):
                e = gcd(d, c)
                ans += e * fact(3) // fact(3 - len(set([a, b, c])) + 1)

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin


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


def fact(x):
    if x == 1:
        return x
    return x * fact(x - 1)


def main():
    k = int(stdin.readline())

    ans = 0

    for a in range(1, k + 1):
        for b in range(a, k + 1):
            d = gcd(a, b)
            for c in range(b, k + 1):
                e = gcd(d, c)
                ans += e * fact(3) // fact(3 - len(set([a, b, c])) + 1)

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from math import factorial

from sys import stdin


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


def main():
    k = int(stdin.readline())

    ans = 0

    for a in range(1, k + 1):
        for b in range(a, k + 1):
            d = gcd(a, b)
            for c in range(b, k + 1):
                e = gcd(d, c)
                ans += e * factorial(3) // factorial(3 - len(set([a, b, c])) + 1)

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import math

K=int(input())

total=0

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

print(total)

Solution (Python):
import sys
import os
import itertools

def file_input():
    f = open('Beginner_Contest_162/input.txt', 'r')
    sys.stdin = f

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

def main():
    
    K=int(input())
    
    sum=0

    combi_l = itertools.combinations_with_replacement(range(1,K+1),3)
    

    for combi in combi_l:
        
        if combi[0]==combi[1]==combi[2]:
            sum+=gcd(gcd(combi[0],combi[1]),combi[2])
        elif combi[0]==combi[1] or combi[1]==combi[2] or combi[2]==combi[0]:
            sum+=3*gcd(gcd(combi[0],combi[1]),combi[2])
        else:
            sum+=6*gcd(gcd(combi[0],combi[1]),combi[2])

    
    
    
    
    

    print(sum)

if __name__ == '__main__':
    main()

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

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

Solution (Python):
import math
num = (int)(input())
total = 0

for i in range(1, num + 1):
  for j in range(1, num + 1):
    sub = math.gcd(i, j)
    for k in range(1, num + 1):
      total += math.gcd(sub, k)
print(total)

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

l = []
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

for i in range(1, k+1):
    for j in range(1, k+1):
        for m in range(1, k+1):
            n = gcd(i, j, m)
            l.append(n)
print(sum(l))

Solution (Python):
import math

k=int(input())
s=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):
      abc=math.gcd(ab,c)
      s+=abc
      
print(s)

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

k = int(input())
sum = 0

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

print(sum)

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

print(ans)

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

print(ans)

Solution (Python):
import itertools
K = int(input())
ans = 0
S = list(range(1,K+1))
def gcd(a,b):
  while a != 0 or b != 0:
    if a % b == 0:
      return min(a,b)
    a, b = b, a % b
for v in itertools.combinations_with_replacement(S, 3):
  if v[0] == v[1] == v[2]:
    ans += v[0]
  elif v[0] != v[1] and v[1] != v[2] and v[0] != v[2]:
    ans += gcd(gcd(v[0],v[1]),v[2])*6
  else:
    ans += gcd(gcd(v[0],v[1]),v[2])*3

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

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

Solution (Python):
import itertools
K = int(input())
ans = 0
S = list(range(1,K+1))
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) 
for v in itertools.combinations_with_replacement(S, 3):
  if v[0] == v[1] == v[2]:
    ans += v[0]
  elif v[0] != v[1] and v[1] != v[2] and v[0] != v[2]:
    ans += gcd(gcd(v[0],v[1]),v[2])*6
  else:
    ans += gcd(gcd(v[0],v[1]),v[2])*3

print(ans)

Solution (Python):


import math

K = int(input())

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

print(ans)