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



Sample input:
2


Sample output:
9

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 

K = INT()
 
many_gcd = lambda numbers: reduce(gcd, numbers)
 
ans = 0
for i in range(1, K+1):
	for j in range(1, K+1):
		for k in range(1, K+1):
			ans += many_gcd([i, j, k])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())

result=[]
count=0
cnt=0
def gcd(a,b):
  for i in range(200):
    if b!=0:
      a,b=b,a%b
    if b==0:
      break
  return a

 
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)

Submission status: Time Limit Exceeded

Solution code:
import functools
from fractions import gcd
n = int(input())
@functools.lru_cache(None)
def main(n):
  g=0
  for i in range (1, n+1):
    for j in range (1, n+1):
      for k in range (1, n+1):
        g  += gcd(gcd(i,j),k)
  return (g)
print(main(n))

Submission status: Time Limit Exceeded

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

N = int(input())

ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
import math
k = int(input())
x = 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(math.gcd(a, b), c)
print(x)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 21:45:38 2020
 
@author: H_Hoshigi
"""
 
import math
 
K = int(input())
 
answer = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            answer += math.gcd(math.gcd(a, b), c)
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import fractions
K = int(input())

i=0
dammy=[0]*(K*K*K)
for a in range(1,K+1):
    for b in range(1,K+1):
        f=fractions.gcd(a,b)
        for c in range(1,K+1):


            ff = fractions.gcd(f,c)
            #dammy.append(ff)
            dammy[i]=ff
            i+=1

print(sum(dammy))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def gcd_(a, b):
    if a % b == 0: return b
    return gcd_(b, a % b)

k = int(input())
res = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for m in range(1, k+1):
            res += gcd_(gcd_(i, j), m)

print(res)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
ans=0
from fractions import gcd
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):
            ans+=gcd(c,t)
print(ans)

Submission status: Time Limit Exceeded

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

def main():
    args = input().rstrip().split(' ')
    K = int(args[0])
    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(gcd(a,b), c)
    print(sum_)
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
ans=0
from fractions import gcd
import functools 
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            @functools.lru_cache(None) 
            def gc(x,y):
                if x>y:
                    x,y=y,x
                return gcd(x,y)

            ans+=gcd(a,gcd(b,c))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def find_gcd(x, y):
    while(y): 
        x, y = y, x % y 
    return x


nums = int(input())
result = 0

for i in  range(1, nums+1):
    for j in range(1, nums+1):
        for l in range(1, nums+1):
            result += find_gcd(find_gcd(i, j), l)

print(result)

Submission status: Time Limit Exceeded

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


ans = 0
k = int(input())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
g=[201*[0]for _ in range(201)]
for i in range(1,201):
  for j in range(i,201):
    g[i][j]=gcd(i,j)
ans=0
for i in range(1,201):
  for j in range(1,201):
    for k in range(1,201):
      m=g[min(i,j)][max(i,j)]
      ans+=g[min(k,m)][max(k,m)]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

def main():
    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) 

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools

N=int(input())

GCD=[]
GCD1=[]
for i in range (1,N+1):
	GCD.append(i)
 
for i in itertools.product(GCD,repeat=3):
   
	GCD1.append(math.gcd(math.gcd(i[0],i[1]),i[2]))
 
print(sum(GCD1))

Submission status: Time Limit Exceeded

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


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

Submission status: Time Limit Exceeded

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

k = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())
res = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for m in range(1, k+1):
            res += math.gcd(math.gcd(i, j), m)

print(res)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
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 += reduce(gcd, [i, j, k])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions

def GCD(a,b,c):
    return fractions.gcd(fractions.gcd(a,b),c)

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
 
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
 
s = 0
for h in range(1, k+1):
    for j in range(1, k+1):
        for k in range(1, k+1):
            s = s + gcd(h, gcd(j, k))
 
print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = gcd(x, a[i])
    return x

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

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
from functools import reduce
N=int(input())
def A(i):
    def gcd(*numbers):
        return reduce(math.gcd, numbers)

    GCD=[]
    GCD1=[]
    for i in range (1,N+1):
        GCD.append(i)

    for i in itertools.product(GCD,repeat=3):
   
        GCD1.append(gcd(i[0],i[1],i[2]))
    
    return sum(GCD1) 

print(A(N))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
import fractions
total=0
for A in range(1,n+1):
  for B in range(1,n+1):
    for C in range(1,n+1):
      a=[A,B,C]
     
      ans = a[0]
      for i in range(1,3):
        ans=fractions.math.gcd(ans,a[i])
       
      total=total+ans
print(total)

Submission status: Time Limit Exceeded

Solution code:

from math import gcd
from functools import reduce
s = 0

k = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
N = int(input())

ll = [i for i in range(1,N+1)]   
ans = 0

for i in ll:
    for j in ll:
        s = gcd(i,j)
        for k in ll:
            ans += gcd(s,k)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
N = int(input())

ll = [i for i in range(1,N+1)]   
ans = 0

def aaa(a):
    d = gcd(a[0],a[1])
    return gcd(d,a[2])

lll = []
for i in ll:
    for j in ll:
        for k in ll:
            lll.append((i ,j, k))

for ii in lll:
    ans += aaa(ii)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
# a,b,c=map(int,input().split())
cnt=0
def gcd(a,b):
    if a==0: return b
    else: return gcd(b%a,a)
# print(gcd(a,b))

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

for i in range(1,n+1):
    for j in range ( 1 , n + 1 ):
        for k in range ( 1 , n + 1 ):
            # print(i,j,k)
            cnt+=gcd_3(i,j,k)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import collections

k = int(input())

dict = collections.defaultdict(list)
mdict = collections.defaultdict(list)

def gcd(a,b):
    global mdict
    # if mdict[tuple(sorted[a,b])]!= None:
    #     return mdict[tuple(sorted[a,b])]
    if b == 0:
        # mdict[tuple(sorted[a,b])] = a
        return a
    else:
        return gcd(b, a % b)

def mgcd(i,j,x):
    global dict
    if dict.get(tuple(sorted([i,j,x])))!=None:
        # print("recall")
        # print(i,j,)
        return dict[tuple(sorted([i,j,x]))]
    else:
        g = gcd(i,gcd(j,x))
        # print(g)
        dict[tuple(sorted([i,j,x]))]= g
        return g

sum = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        for x in range(1,k+1):
            
            g = mgcd(i,j,x)
            # print(g)
            sum+=g

print(sum)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
import numpy as np
q = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            q = q + np.gcd.reduce([i,np.gcd.reduce([j,k])])
print(q)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

def main():
    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(i,j,k)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#C-2

#最大公約数を返す関数
def gcd(a,b,c):
    a_d = []
    b_d = []
    c_d = []
    d = []

    for i in range(1,a+1):
        if a % i == 0:
            a_d.append(i)

    for i in range(1,b+1):
        if b % i == 0:
            b_d.append(i)

    for i in range(1,c+1):
        if c % i == 0:
            c_d.append(i)

    d = list(set(a_d)&set(b_d)&set(c_d))

    return max(d)


#入力値
k = int(input())

ans = [gcd(a,b,c) for a in range(1,k+1) for b in range(1,k+1) for c in range(1,k+1) ]

print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

K = int(input())
ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
K=int(input())+1
sum=0
for a in range(1,K):
    for b in range(1,K):
        for c in range(1,K):
            AB = gcd(a,b)
            BC = gcd(b,c)
            ABC = gcd(AB,BC)
            sum = sum+ABC
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
N = int(input())
ans = 0
for i in range(1,N+1):
  for k in range(1,N+1):
    for l in range(1,N+1):
      if i == k and k == l:
        tmp = i
      elif i==k:
        tmp = gcd(k,l)
      elif k==l:
        tmp = gcd(l,i)
      elif l==i:
        tmp = gcd(i,k)

      else:
        a = l 
        b = k
        c = i
        d = gcd(a,b)
        e = gcd(b,c)
        tmp = gcd(d,e)
      ans += tmp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
import itertools

def my_gcd(n):
    return reduce(fractions.gcd,n)

K=int(input())
sum=0

for i,n,m in itertools.product(range(1,K+1),range(1,K+1),range(1,K+1)):
    sum+=my_gcd([i,n,m])

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math

from collections import defaultdict
from collections import deque
from math import gcd
def load(vtype=int):
    return vtype(input().strip())

def exit():
    import sys
    sys.exit(0)



d = dict()
d2 = dict()

def check(a, b, d2):
    t = tuple(sorted([a,b]))
    if t in d2:
        return d2[t]
    return False

k = load()
s = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1, k+1):
            r = check(i, j, d2)
            target = None
            if r:
                target = k
            else:
                r = check(j, k, d2)
                if r:
                    target = i
                else:
                    r = check(i, k, d2)
                    if r:
                        target = j
                    else:
                        # print(i,j,k)
                        d2[(i,j)] = gcd(i,j)
                        r = d2[(i,j)]
                        target = k
            r2 = check(r, target, d2)
            if r2:
                s += r2
            else:
                d2[(r, target)] = gcd(r, target)
                s += d2[(r, target)]

print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
k=int(input())
sum=0
for l in range(1,k+1):
    for m in range(1,k+1):
        for n in range(1,k+1):
            sum += math.gcd(math.gcd(l,m),n)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
k = int(input())
result = 0

# 3つとも等しい数字
for i in range(1, k+1):
    for j in range(i, k+1):
        for m in range(j, k+1):
            if i==j==m:
                result += i
            elif i==j or j==m:
                result += gcd(i, m)*3
            else:
                result += gcd(i, gcd(j,m))*6
print(result)

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
import math

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

K = i_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 += math.gcd(math.gcd(a,b), c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
k=int(input())
sum=0
for l in range(1,k+1):
    for m in range(1,k+1):
        for n in range(1,k+1):
            sum += gcd(gcd(l,m),n)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
from functools import reduce


k = int(input())

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

k += 1
ans = 0

#for i in range(1,k):
#    for j in range(i,k):
#        #print(i,j)
#        if i == j:
#            ans += gcd(i,j)
#        else:
#            ans += gcd(i,j)*6

for i in range(1,k):
    for j in range(1,k):
        for h in range(1,k):
            #print(i,j,h)
            ans += gcd_(i,j,h)


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
K = int(input())
 
lis = [i for i in range(1,K+1)]
a = 0
 
n = list(itertools.product(lis, repeat=3))
for i in range(len(n)):
    ma = math.gcd(math.gcd(n[i][0],n[i][1]),math.gcd(n[i][0],n[i][2]))
    a += ma
print(a)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
from math import gcd
import itertools

def main():
    k = int(input())
    ans = 0
    num = [i for i in range(1,k+1)]
    comb = tuple(itertools.product(num, repeat=3))

    for i in comb:
        ans += gcd(gcd(i[0], i[1]), i[2])

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np

K = int(input())

gcdSum = 0

myArr = np.zeros((K, K), dtype=int)

for iIndx in range(K):
    for jIndx in range(K):
        myArr[iIndx, jIndx] = math.gcd(iIndx+1, jIndx+1)

for iIndx in range(K):
    for jIndx in range(K):
        presGcd = myArr[iIndx, jIndx]
        for kIndx in range(K):
            gcdSum += myArr[presGcd-1, kIndx]

print(gcdSum)

Submission status: Time Limit Exceeded

Solution code:
#C

#最大公約数を返す関数
def gcd(a,b,c):
    a_d = []
    b_d = []
    c_d = []
    d = []

    for i in range(1,a+1):
        if a % i == 0:
            a_d.append(i)

    for i in range(1,b+1):
        if b % i == 0:
            b_d.append(i)

    for i in range(1,c+1):
        if c % i == 0:
            c_d.append(i)

    d = list(set(a_d)&set(b_d)&set(c_d))

    return max(d)


#入力値
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 = ans + gcd(a,b,c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
K = int(input())
 
ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        gcd_ij = np.gcd(i, j)
        for k in range(1, K + 1):
            ans += np.gcd(gcd_ij, k)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
total = 0
 
def gcd(a, b):
    if(a > b):
        a, b = b, a
 
    while(b > 0):
        r = a % b
        a = b
        b = r
 
    return a
 
 
for a in range(1, K+1):
    for b in range(1, K+1):
        res = gcd(a, b)
        for c in range(1, K+1):
           total += gcd(res, c)
 
 
print(total)

Submission status: Time Limit Exceeded

Solution code:
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):
            for k in range(1, N + 1):
                ans += sgcd(sgcd(i, j), k)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

Solution code:
from fractions 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)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

K=int(input())
sum=0

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
def gcd(a, b):
    if b == 0:
        return a
    else:
        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)

Submission status: Time Limit Exceeded

Solution code:
import math as m

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np
result = 0
n = int(input())
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            result +=  np.gcd.reduce((i,j,k))
print(result)

Submission status: Time Limit Exceeded

Solution code:
import math

K=int(input())
sum=0

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

Submission status: Time Limit Exceeded

Solution code:
import math
k = int(input())
total = 0
gcd_ab = 0

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

print(total)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
def main(): #startline-------------------------------------------
    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)
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Time Limit Exceeded

Solution code:
import math as f

K = int(input())
total = 0

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

print(total)

Submission status: Time Limit Exceeded

Solution code:
from numpy import gcd 
K = int(input())+1
cnt = 0
for a in range(1,K):    
    for b in range(1,K):
        for c in range(1,K):
            cnt+=gcd((gcd(b,c)),a)        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math
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):
      S += math.gcd(math.gcd(a, b), c)
print(S)

Submission status: Time Limit Exceeded

Solution code:
import fractions
K=int(input())
ans=0
A=0

for n in range(1,K+1):
    for m in range(1,K+1):
      gcd1=fractions.gcd(n,m)
      for l in range(1,K+1):
          A=fractions.gcd(gcd1,l)   
          ans+=A
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

SUM=0
for i in range(1, K+1):
        a = i
        for j in range(1, K+1):
                a = i
                b = j
                while b != 0:
                        a, b = b, a%b
                for k in range(1, K+1):
                        d = a
                        c = k
                        while c != 0:
                                d, c = c, d%c
                        SUM += d

print(SUM)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

k = int(input()) + 1


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


def counter(num):
    count = 0
    for a in range(1, num):
        for b in range(1, num):
            t = gcd(a,b)
            for c in range(1, num):
                    count += gcd(t, c)
    print(count)

counter(k)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

##def gcd(a, b, c, cnt):
  ##  i = 0
    ####  i = i + 1
        ##if len(list(filter(is_prime, [a, b, c]))) == 0:
          ##  if (a % i == 0) and(b % i == 0) and (c % i == 0):
            ##    return gcd(a / i, b / i, c / i, cnt * i)
        ##else:
          ##  return cnt

def is_prime(n):
    if n % 2 == 0 and n > 2:
        return False
    return all(n % i for i in range(3, int(math.sqrt(n)) + 1, 2))

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
import math

#n = map(int,input().split())

k = int(input())


def gcd(a,b):
    if a > b:
        a , b = b , a

    # q = b / a
    r = b % a

    if r == 0:
        return a
    else:
        return gcd(a,r)
    

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
K=int(input())
ans=0
 
for n in range(1,K+1):
    for m in range(1,K+1):
      gcd1=fractions.gcd(n,m)
      for l in range(1,K+1):
            ans+=fractions.gcd(gcd1,l)   
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
def multi_gcd(a):
    ans = a[0]
    for i in range(1, len(a)):
        ans = math.gcd(ans, a[i])
    #print(ans)
    return ans
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_ += multi_gcd([i, j, k])
print(sum_)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
 
K = int(input())
l = range(1, K+1)
ans = 0
 
for a, b, c in itertools.product(l, repeat=3):
    ans += math.gcd(math.gcd(a, b), c)
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
ans=0
k=int(input())
for x in range(1,k+1):
    for y in range(1,k+1):
        for z in range(1,k+1):
            ans+=gcd(x,gcd(y,z))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
n = int(input())
a, b, c = 1, 1, 1
sum = 0
while True:
    sum += gcd(gcd(a, b), c)
    if n > c:
        c += 1
    elif n == c and n == b and n == a:
        break
    elif n == c and n == b:
        a += 1
        b = 1
        c = 1
    elif n == c:
        b += 1
        c = 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import fractions
K=int(input())
ans=0
 
for n in range(1,K+1):
    for m in range(1,K+1):
      gcd1=fractions.gcd(n,m)
      for l in range(1,K+1):
            gcd2=fractions.gcd(gcd1,l)
            
            ans+=gcd2
   
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from fractions 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()

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
def gcd(*number):
    return reduce(math.gcd, number)
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, j, k)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())

gcdSum = 0

for iIndx in range(1, K+1):
    for jIndx in range(1, K+1):
        for kIndx in range(1, K+1):
            gcdSum += math.gcd(math.gcd(iIndx, jIndx), kIndx)

print(gcdSum)

Submission status: Time Limit Exceeded

Solution code:
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
from fractions import gcd
 
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
c = 0
K = INT()
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):
            b = gcd(a, k)
            ans += b
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
K=int(input())
ans=0
 
for n in range(1,K+1):
    for m in range(1,K+1):
        for l in range(1,K+1):
            gcd=fractions.gcd(n,m)
            gcd=fractions.gcd(gcd,l)
            
            ans+=gcd
   
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions 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(i,gcd(j,k))
print(ans)

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def gcd_3(i,j,k):
    return gcd(gcd(i,j),k)
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_3(i,j,k)
print(ans)