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 functools import lru_cache


@lru_cache(maxsize=None)
def gcd(a, b):
    if a < b:
        a, b = b, a
    if a % b == 0:
        return b
    return gcd(b, a % b)


def main():
    ans = 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):
                ans += gcd(gcd(i, j), l)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin
from math import gcd
def main():
    
    readline=stdin.readline
    k=int(readline())
    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)
if __name__=="__main__":
    main()

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

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

h=1
ans=0
while h<=k:
    i=1
    while i<=k:
        j=1
        while j<=k:
            ans += gcd(gcd(h,i),j)
            j+=1
        i+=1
    h+=1

print(ans)

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

Solution (Python):
import math

K = int(input())

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

print(ans)

Solution (Python):
import math

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

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, b, c)

print(ans)

Solution (Python):
import math
from functools import reduce

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

k = int(input())

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

print(ans)

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

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

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

ans = 0

for a in range(1,k+1):
    ans +=gcd(a,a,a)

for a in range(1,k+1):
    for b in range(1,k+1):
        if a!=b:
            ans += 3*gcd(a,a,b)

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


print(ans)

Solution (Python):
import math

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

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

Solution (Python):
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
K = int(input())
s=0
q=0
w=0
e=0
for i in range(K):
    q+=gcd(i+1,i+1,i+1)
    
for a in range(K):
    for b in range(K):
        if not a==b:
            w+=3*gcd(a+1,a+1,b+1)
for a in range(1,K-1):
    
    for b in range(a+1,K):
     
        for c in range(b+1,K+1):
      
            e+=6*gcd(a,b,c)

print(q+w+e)

Solution (Python):
import time
def gcd1(x,y):
    d = x % y
    while d != 0:
        x,y = y,d
        d = x % y
    return y

def gcd(x,y):
    if x == 1 or y == 1:
        return 1
    if x < y:
        x,y = y,x
    return gcd1(x,y)

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

K = int(input())
t1 = time.time()
ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            ans += gcd3(a,b,c)
t2 = time.time()
print(ans)

Solution (Python):
import sys
from collections import deque
import copy
from math import gcd
def main():
    K = int(input())
    a = []
    for i in range(1, K+1):
        for j in range(1, K+1):
            a.append(gcd(i, j))
    count = 0
    for i in range(1, K+1):
        for j in range(len(a)):
            count += gcd(i, a[j])
    print(count)


if __name__ == '__main__':
    main()

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

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


a = [i for i in range(1,K+1)]

x = itertools.combinations(a,2)
y = itertools.combinations(a,3)

c = 0
for i,j in x:
  c += math.gcd(i,j)

d = 0
for i,j,k in y:
  d += math.gcd( math.gcd(i,j) , k)

ans = sum(a) + c*6 + d*6

if K == 1:
  ans = 1
elif K == 2:
  ans = 9

print(ans)

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

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

print(ans)

Solution (Python):
K = int(input())
def calcgcd(a, b):
  if a > b:
    a, b = b, a
  while a > 0:
    a, b = b%a, a
  return b
r = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    ab = calcgcd(a, b)
    for c in range(1, K+1):
      g = calcgcd(ab, c)
      r += g
print(r)

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


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


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 fractions import gcd
K = int(input())


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


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

print(ans)

Solution (Python):
from math import gcd

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

Solution (Python):
import math
from functools import reduce

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

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

Solution (Python):
import math
g = 0
K = int(input())
for a in range(1,K-1):
    for b in range(a+1,K):
        for c in range(b+1,K+1):
            g += math.gcd(math.gcd(a,b),c)*6
for d in range(1,K):
    for e in range(d+1,K+1):
        g+= math.gcd(d,e)*6
g+= K*(K+1)//2
print(g)

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 itertools import product
from math import gcd

K = int(input())

print(sum([gcd(gcd(a, b), c) for a, b, c in product(range(1, K + 1), repeat=3)]))

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

def ep(*params):
    print(*params,file=sys.stderr)

def gcd(s1,s2):
    s = (s1,s2)
    global total,hit
    return math.gcd(s1,s2)
    
K = int(input().rstrip())
ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        ab = gcd(a,b)
        if ab == 1:
            ans += 1*K
        else:
            for c in range(1,K+1):
                ans += gcd(ab,c)

print(ans)

Solution (Python):
import math

def gcd(a,b,c):
    d = math.gcd(a, b)

    return math.gcd(c,d)

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,b,c)

print(sum)

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

Solution (Python):
import math

K = int(input())

Sum = []
for a in range(1, K+1):
    for b in range(1, K + 1):
        gcd2 = math.gcd(a, b)
        for c in range(1, K + 1):
            gcd = math.gcd(gcd2, c)
            Sum.append(gcd)

print(sum(Sum))

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

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=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=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):
K = int(input())
import math
from functools import reduce
G = []
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):
            gc = math.gcd(g,c)
            G.append(gc)
print(sum(G))

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

Solution (Python):


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

print(ans)

Solution (Python):
import math

K = int(input())

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

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

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

print(ans)

Solution (Python):
import math

k = int(input())
hi_gcd = 1
gcd = 1
ans = 0

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

print(ans)

Solution (Python):
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)

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

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

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

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

print(Sum)

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

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

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

sum = 0
k = int(input())
l = range(1,k+1)

for a,b,c in combinations_with_replacement(l, 3):
    ans = gcd(a,b,c)
    if a == b and a == c:
        sum += ans
    elif a == b or b == c or c == a:
        sum += 3 * ans
    else:
        sum += 6 * ans

print(sum)

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

import math

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):
from math import gcd
K = int(input())
l = 0
for A in range(1, K + 1):
  for B in range(1, K + 1):
    for C in range(1, K + 1):
      l += gcd(gcd(A,B), C)
      
print (l)

Solution (Python):
import math

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

        total = 0

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

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

if __name__=="__main__":
        main()

Solution (Python):
from math import gcd
from functools import reduce
def gcds(*numbers):
  return reduce(gcd, numbers)
K = int(input())
ans1 = 0
ans2 = 0
ans3 = 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 and b == c:
        ans1 += gcds(a, b, c)
      elif a == b or b == c or c == a:
        ans2 += gcds(a, b, c)
      else:
        ans3 += gcds(a, b, c)
print(ans1 + 3 * ans2 + 6 * ans3)

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

print(answer)

Solution (Python):
import math

def gcd(k):
  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)  
  
if __name__ == "__main__":
  k = int(input())
  gcd(k)

Solution (Python):
from math import gcd


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

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


if __name__ == "__main__":
    main()

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

Solution (Python):

from sys import stdin
import math

def I(): return int(stdin.readline().rstrip())


k = I()

ans = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        tmp = math.gcd(i,j)
        if tmp != 1 :
            for w in range(1,k+1):
                ans += math.gcd(tmp,w)
        else:
            ans += k

print(ans)

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

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

def main():
    K = int(input())
    memo = [[-1] * 201 for i in range(201)]
    
    for a in range(1, 201):
        for b in range(1, 201):
            memo[a][b] = gcd(a, b)
    
    ans = 0
    for a in range(1, K+1):
        for b in range(1, K+1):
            for c in range(1, K+1):
                ans += memo[memo[a][b]][c]
    print(ans)

if __name__ == "__main__":
    main()

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

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

Solution (Python):
k = int(input())
ans=0
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x
 
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):
from sys import stdin, setrecursionlimit


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


def main():
    input = stdin.buffer.readline
    k = int(input())
    g = []
    for i in range(1, k + 1):
        gi = []
        for j in range(1, k + 1):
            gi.append(gcd(i, j))
        g.append(gi)
    ans = 0
    for a in range(k):
        for b in range(k):
            for c in range(k):
                tmp = g[a][b] - 1
                ans += g[tmp][c]
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

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

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

print(res)

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

K=int(input())
ans=0
for a in range(1,K+1):
  for b in range(1,K+1):
    ab=gcd(a,b)
    if ab == 1:
      ans += K
    else:
      for c in range(1,K+1):
        ans += gcd(ab,c)
print(ans)

Solution (Python):
import math

k = int(input())
sum = 0
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):
from math import gcd
K = int(input())

s=0
for i in range(1,K+1):
    for j in range(1, K+1):
        for l in range(1, K+1):
            s += gcd(i, gcd(j,l))

print(s)

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

v = int(input())
sum = 0

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

print(sum)

Solution (Python):
import math
from functools import reduce

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

K = int(input())

total = 0
for l in range(1,K+1):
  for m in range(1,K+1):
    for n in range(1,K+1):
      total += gcd([l, m, n])

print(total)

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

N = int(input())
sum = 0

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

Solution (Python):
import fractions
K = int(input())
ans = 0
dp = []
for i in range(0,K+1):
    dpp = []
    for j in range(0,K+1):
        dpp.append(0)
    dp.append(dpp)
def dpgcd(a,b):
    if dp[a][b] != 0:
        return dp[a][b]
    else:
        gg = fractions.gcd(a,b)
        dp[a][b] = gg
        dp[b][a] = gg
        return gg
for i in range(0,K):
    for j in range(0,K):
        g = dpgcd(i+1,j+1)
        for k in range(0,K):
            ans += dpgcd(g,k+1)
print(ans)

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

for a in range(1,K+1):
  for b in range(a+1,K+1):
    for c in range(b+1,K+1):
      total += math.gcd(a, math.gcd(b,c) ) * 6
      
for a in range(1,K+1):
  for b in range(a+1,K+1):
    total += math.gcd(a, b)*6

for a in range(1,K+1):
  total += a

print(total)

Solution (Python):
import math
from functools import reduce

ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

k=ni()

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

print(ans)

Solution (Python):
import math
k=int(input())
ans=0
for p in range(1,k+1):
    for q in range(1,k+1):
        gcd=math.gcd(p,q)
        for r in range(1,k+1):
            ans=ans+math.gcd(gcd,r)
print(ans)

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

Solution (Python):


import math

def main():
    number_of_digit = int(input())
    
    result = 0
    for first in range(1,number_of_digit+1):
        for second in range(1,number_of_digit+1):
            first_gcd = math.gcd(first,second)
            if first_gcd == 1:
                result += number_of_digit
            else:
                for third in range(1,number_of_digit+1):
                    second_gcd = math.gcd(first_gcd,third)
                    result += second_gcd
    print(result)
            
if __name__ == "__main__":
    main()

Solution (Python):

import math
from functools import reduce

tmp = input().split()
K = int(tmp[0])

SGCD = 0


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







        



for c in range(K+1)[1:]:
    for b in range(c+1)[1:]:
        for a in range(b+1)[1:]:
            if not a == b and not b == c:
                SGCD = SGCD + 6*gcd(a,b,c)
            elif a == b and not b == c:
                SGCD = SGCD + 3*gcd(a,b,c)
            elif not a == b and b == c:
                SGCD = SGCD + 3*gcd(a,b,c)
            elif a == b and b == c:
                SGCD = SGCD + gcd(a,b,c)

print(int(SGCD))

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


def solve(string):
    k = int(string)
    ans = 0
    for a, b, c in product(range(1, k + 1), repeat=3):
        ans += gcd(gcd(a, b), c)
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
import math


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

print(S)

Solution (Python):
import math 
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
    
 
a = int(input())
 
ans = 0
 
for i in range(1,a+1):
    for j in range(1,i+1):
        for k in range(1,j+1):
            if i == j and i == k:
                ans += gcd(i,j,k)
            elif i == j or i == k or j == k:
                ans += gcd(i,j,k)*3
            else:
                ans += gcd(i,j,k)*6
print(ans)

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

Solution (Python):
import math
n = int(input())
scores = 0
for a in range(1, n+1):
    for b in range(1, n+1):
        gcd_ab = math.gcd(a, b)
        for c in range(1, n+1):
            score = math.gcd(gcd_ab, c)
            scores += score
print(scores)

Solution (Python):
import math

K = int(input())

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

print(S)

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

ans = 0

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

print(ans)

Solution (Python):
import math

def main():
    K = int(input())
    r = 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):
                r += math.gcd(t, k)
    print(r)

if __name__ == '__main__':
    main()

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

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

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

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

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


def gcd(a, b, c):
    n = 1
    if a == b:
        if b != c:
            n = 3
    else:
        if b != c:
            n = 6
        else:
            n = 3
    return math.gcd(math.gcd(a, b), c) * n


def resolve():
    K = int(input())
    T = [i for i in range(1, K + 1)]
    Tr = itertools.combinations_with_replacement(T, 3)
    sumT = 0
    for a, b, c in Tr:
        sumT += gcd(a, b, c)
    print(sumT)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2"""
        output = """9"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """200"""
        output = """10813692"""
        self.assertIO(input, output)

    def test_add(self):
        input = """195"""
        output = """9997134"""
        self.assertIO(input, output)


if __name__ == "__main__":
    
    resolve()

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

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

K = int(input())

t = []

for i in range(1, K+1):
    s = 0
    
    for j in range(1, K+1):
        s += gcd(i, j)
    t.append(s)
    
ans = 0

for i in range(1, K+1):
    for j in range(1, K+1):
        ans += t[gcd(i, j)-1]
        
print(ans)

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

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

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

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

Solution (Python):
from functools import lru_cache, reduce
from math import gcd

K = int(input())

memo_b = [[None for _ in range(K)] for _ in range(K)]

def c_gcd(a, b):
    if memo_b[a-1][b-1] is not None:
        return memo_b[a-1][b-1]
    else:
        res = gcd(a, b)
        memo_b[a-1][b-1] = res
    return res

ans = 0
for i in range(1, K+1):
    for j in range(i+1, K+1):
        ans += 6 * c_gcd(i, j)
        for k in range(j+1, K+1):
            ans += 6*c_gcd(c_gcd(i, j), k)


for i in range(1, K+1):
    ans += i

print(ans)

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

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

Solution (Python):
import itertools

k = int(input())
comb = list(itertools.combinations_with_replacement([i for i in range(1,k+1)], 3))
ans = 0
for a,b,c in comb:
  permutation = len(set([a,b,c]))
  r = b % a
  while r > 0:
    b = a
    a = r
    r = b % a
    
  r = c % a
  while r > 0:
    c = a
    a = r
    r = c % a
    
  if permutation == 3:
    ans += 6 * a
  elif permutation == 2:
    ans += 3 * a
  else:
    ans += a
    
print(ans)

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

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

mem = dict()
s = 0


def gcd(n1, n2):
    while n2 != 0:
        n3 = n1 % n2
        n1 = n2
        n2 = n3
    return n1


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


print(s)

Solution (Python):
import math



K=int(input())
sum=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):
            sum+=math.gcd(a,k)
print(sum)

Solution (Python):
import math
k = int(input())
d = [math.gcd(a, b) for a in range(1, k + 1) for b in range(1, k + 1)]
ans = [math.gcd(c, di) for c in range(1, k + 1) for di in d]
print(sum(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 l in range(1,k+1):
            ans += math.gcd(a,l)
print(ans)