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 math
from functools import reduce

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

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

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

def gcd(a,b,c):
    m = min(a,b,c)
    for i in range(m,1,-1):
        if(a%i==0 and b%i==0 and c%i==0):
            return i
    return 1

ans = 0
for a in range(1,k+1):
    for b in range(a,k+1):
        for c in range(b,k+1):
            n = len(set([a,b,c]))
            if n==2:
                ans += gcd(a,b,c)*3
            elif n==3:
                ans += gcd(a,b,c)*6
            else:
                ans += gcd(a,b,c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:

import sys

sys.setrecursionlimit(100000)

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


k = int(input())

x = 0

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

print(x)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

def gcd(A,B,C):
    output = 1
    mini = min(A,B,C)
    for i in range(mini + 1,1,-1):
        if ((A%i == 0) and (B%i == 0) and (C%i == 0)):
            output = i
            break
    return output

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):
            if ((A == B) and (A == C)):
                sum = sum + A
            elif((B == C) and ( A != C)):
                sum = sum + (3 * gcd(A,B,C))
            elif(((A == B) and (A != C)) or ((A == C) and (A != B))):
                sum = sum + 0
            else:
                sum = sum + gcd(A,B,C)
print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import (
    accumulate,  # 累積和のイテレータ
    groupby,  # 値をkey,同じ値の集まりをgroup
    permutations,  # 順列
    combinations,  # 組み合わせ
    product,  # 重複あり順列（直積, 深いネストにも使える）
    combinations_with_replacement,  # 重複あり組み合わせ
)

import fractions
from functools import reduce

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

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


N = int(input())
ans = 0
for i, j, k in combinations_with_replacement(range(1, N+1), 3):
    if i==j==k:
        ans += i
    elif i==j:
        ans += gcd(i, k)*3
    elif j==k:
        ans += gcd(j, i)*3
    elif i==k:
        ans += gcd(i, j)*3
    else:
        ans += gcd_list([i, j, k])*6
print(ans)

Submission status: Time Limit Exceeded

Solution code:
y=int(input())
b=[[i,j,k]  for i in range(1,y+1) for j in range(1,y+1) for k in range(1,y+1) ]
c=[]
for l in range(y**3):
    import math
    a = b[l]
    ans = a[0]
    ans1 = math.gcd(ans, a[1])
    ans2 =math.gcd(ans,a[2])
    ans3 =math.gcd(ans1,ans2)
    c.append(ans3)
print(sum(c))

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

k = int(input())
tmp = 0
for a in range(1, k+1):
  for b in range(a, k+1):
    for c in range(b, k+1):
      #print('a='+str(a)+', b='+str(b)+', c='+str(c))
      if a == b and a == c:
        tmp += gcd_list([a, b, c]) 
      elif a == b and a != c:
        tmp += gcd_list([a, b, c]) 
        tmp += gcd_list([b, c, a]) 
        tmp += gcd_list([c, a, b]) 
      elif b == c and a != c:
        tmp += gcd_list([a, b, c]) 
        tmp += gcd_list([b, c, a]) 
        tmp += gcd_list([c, a, b]) 
      elif a == c and b != c:
        tmp += gcd_list([a, b, c]) 
        tmp += gcd_list([b, c, a]) 
        tmp += gcd_list([c, a, b]) 
      else:
        tmp += gcd_list([a, b, c])
        tmp += gcd_list([a, c, b])
        tmp += gcd_list([b, a, c])
        tmp += gcd_list([b, c, a])
        tmp += gcd_list([c, a, b])
        tmp += gcd_list([c, b, a])
print(tmp)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
from functools import reduce


a = int(input())
b = list(itertools.product(range(1,a+1),repeat=3))
c = 0


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


for i in b:
    n = gcd(i[0], i[1], i[2])
    c += n

print(c)

Submission status: Time Limit Exceeded

Solution code:

def q3():
    import math
    k = int(input())
    sum_n = 0
    gcd_2_dict = {}

    def gcd(n1, n2):
        if n1 < n2:
            sorted_nums = tuple([n1, n2])
        else:
            sorted_nums = tuple([n2, n1])
        if sorted_nums in gcd_2_dict:
            return gcd_2_dict[sorted_nums]
        gcd_num = math.gcd(n1, n2)
        gcd_2_dict[sorted_nums] = gcd_num
        return gcd_num

    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                sorted_nums = sorted([a, b, c])
                sum_n += gcd(gcd(sorted_nums[0], sorted_nums[1]), sorted_nums[2])

    print(sum_n)

q3()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

class GCD:
    def __init__(self):
        self.cache = {}
    def gcd2(self, a, b):
        if (a in self.cache and b in self.cache[a]):
            return self.cache[a][b]
        if (a % b == 0):
            if (a not in self.cache):
                self.cache[a] = {}
            self.cache[a][b] = b
            return b
        return self.gcd2(b, a % b)
    def gcd3(self, a, b, c):
        return self.gcd2(self.gcd2(a, b), c)

a = 1
b = 1
c = 1
result = 0
client = GCD()
while (a <= k):
    b = 1
    while (b <= k):
        c = 1
        while (c <= k):
            result += client.gcd3(a, b, c)
            c += 1
        b += 1
    a += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
from functools import reduce

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

k = int(input())

sum = 0
l = list(range(1, k+1))
for a, b, c in itertools.product(l, l, l):
    sum += gcd(a, b, c)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
def main():
  k = int(input())
  params = [1,1,0]
  count = 0
  
  while params[0] < k or params[1] < k or params[2] < k:
    if params[2] < k:
      params[2] = params[2]+1
    elif params[1] < k:
      params = [params[0],params[1]+1,1]
    elif params[0] < k:
      params = [params[0]+1,1,1]
      
    tmp = gcd(params[0], params[1])
    count += 1 if tmp == 1 else gcd(tmp,params[2])
    
  return count
 
def gcd(val1, val2):
  return val1 if (val2 == 0) else gcd(val2, val1 % val2)
    
print(main())

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

import itertools
import math
from functools import reduce

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

lis = list(range(1,K+1))
S = [gcd_list(team) for team in itertools.product(lis, repeat = 3)]
print(sum(S))

Submission status: Time Limit Exceeded

Solution code:
class GCD:
    def __init__(self):
        self.numlist = dict()
        self.numlist2 = dict()
    def culc(self, K):
        ret = 0
        for i in range(1,K-1):
            for j in range(i+1, K):
                for k in range(j+1,K+1):
                    ret += self.gcd(i,j,k)*6
        
        for i in range(1,K+1):
            for j in range(1,K+1):
                if i != j:
                    ret += self.gcd(i,i,j) * 3
        for i in range(1, K+1):
            ret += self.gcd(i,i,i)

        return ret

    def gcd(self, a,b,c):
        l = [a,b,c]
        l.sort()
        l = tuple(l)
        if l in self.numlist:
            return self.numlist[l]
        else:
            temp_ = self.gcd_(l[0],l[1])
            temp_ = self.gcd_(temp_, l[2])
            self.numlist[l] = temp_
            return temp_

    def gcd_(self,a,b):
        l = (min(a,b), max(a,b))
        if l in self.numlist2:
            return self.numlist2[l]
        else:
            mod = max(a,b) % min(a,b)
            if mod == 0:
                ret = min(a,b)
                self.numlist2[l] = ret
                return ret
            else:
                ret = self.gcd_(min(a,b), mod)
                self.numlist2[l] = ret
                return ret

K = int(input())
gcd = GCD()
ret = gcd.culc(K)
print(ret)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
def gcd_list(numbers):
  return reduce(math.gcd, numbers)


K = int(input())
abc_list = []


for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      abc_list.append([a, b, c])

gcds = [gcd_list(x) for x in abc_list]

print(sum(gcds))

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
k=int(input())
ans=0
for p in range(1,k+1):
  for q in range(1,k+1):
    for r in range(1,k+1):
      ans+=gcd(p,gcd(q,r))
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

def get_gcd(a, b, c):
    min_ab = min(a, b)
    max_ab = max(a, b)
    amari = max_ab % min_ab
    if amari == 0:
        gcd1 = min_ab
    else:
        x = min_ab
        y = amari
        while y != 0:
            amari = x % y
            if amari == 0:
                gcd1 = y
                break
            x = y
            y = amari
    min_2 = min(c, gcd1)
    max_2 = max(c, gcd1)
    amari = max_2 % min_2
    if amari == 0:
        gcd2 = min_2
    else:
        x = min_2
        y = amari
        while y != 0:
            amari = x % y
            if amari == 0:
                gcd2 = y
                break
            x = y
            y = amari

    return gcd2


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 += get_gcd(i, j, l)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
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 += math.gcd(math.gcd(x, y),z)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
import math
from functools import reduce

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

a = int(input())
cost = 0

for i in range(1,a+1):
    for j in range(1,a+1):
        for k in range(1,a+1):
            b = [i,j,k]
            ans = gcd(*b)
            cost += ans

print(cost)

Submission status: Time Limit Exceeded

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

l = [[-1 for _ in range(k+1)] for _ in range(k+1)]

sum = 0
for x1 in range(1,k+1):
  for x2 in range(1,k+1):
    for x3 in range(1,k+1):
      for i in range(1, 2):
        if l[x1][x2] == -1:
          ans = fractions.gcd(x1,x2)
          l[x1][x2] = ans
          l[x2][x1] = ans
        else:
          ans = l[x1][x2]
        if l[ans][x3] == -1:
          ans1 = fractions.gcd(ans,x3)
          l[ans][x3] = ans1 
          l[x3][ans] = ans1
        else:
          ans1 = l[ans][x3]
        
        sum += ans1
 
print(sum)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
ans=0
g=[[0]*(K+1)]*(K+1)
def gcd(x,y):
    if y==0:
        return x 
    return gcd(y,x%y)
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            x=0
            if g[a][b]!=0:
                x=g[a][b]
            else:
                x=gcd(a,b)
            y=0
            if g[x][c]!=0:
                y=g[x][c]
            else:
                y=gcd(x,c)
            ans+=y

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K=int(input())

ans=K**2+(K-1)*K+(K-1)*(K-1)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math


def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)


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


K = int(input())
data = [k+1 for k in range(K)]
result = []
for i, d_i in enumerate(data):
    for j, d_j in enumerate(data[i:]):
        for d_k in data[i+j:]:
            result.append([d_i, d_j, d_k])

s = 0
for r in result:
    r0, r1, r2 = r
    g = gcd(r2, gcd(r0, r1))
    if r0 == r1 == r2:
        s += g
    elif r0 != r1 and r1 != r2:
        s += g * 6
    else:
        s += g * 3

print(s)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import functools
import fractions
 
def gcd(*numbers):
  return reduce(gcd_, numbers)
  # return reduce(fractions.gcd, numbers)

@functools.lru_cache(maxsize=128)
def gcd_(a, b):
  if (b == 0):
    return a
  return gcd(b, a % b)
 
sum = 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):
      sum += gcd(i,j,k)
      
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
from functools import reduce
from itertools import product

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

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

l = int(input())
s = 0
li = list(range(1,l+1))
for i,j,k in product(li, repeat = 3):
  s += gcd(i,j,k)
print(s)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
ans = 0
for a in range(K):
    a += 1
    if a == 1:
        ans += K*K
        continue
    for b in range(K):
        b += 1
        if b == 1:
            ans += K
            continue
        tmp = gcd(a, b)
        for c in range(K):
            c += 1
            if c == 1:
                ans += 1
                continue
            dada = gcd(tmp, c)
            ans += dada
            # print(dada)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
k = int(input())
ans = 0
t = 0
for i1 in range(1, k+1):
    for i2 in range(1, k+1):
        for i3 in range(1, k+1):
            ans = math.gcd(i1, i2)
            ans = math.gcd(ans, i3)
            t+=ans
print(t)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

k = int(input())

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

answer = 0
for i in range(len(abc)):
    answer += np.gcd.reduce(abc[i])

print(answer)

Submission status: Time Limit Exceeded

Solution code:

import numpy as np
import math

k =int(input())
memo = [[[0]*k for _ in range(k)]  for _ in range(k)]
ans = 0

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


print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

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

result = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            result += gcdl(a,b,c)

print(result)

Submission status: Time Limit Exceeded

Solution code:
K_s=input()
K=int(K_s)
ans=0

def gcd_dual(x,y):
    max_num=max(x,y)
    min_num=min(x,y)
    flag=True
    while(flag):
        if max_num%min_num==0:
            flag=False
        else :
            x_num= max_num%min_num
            max_num=min_num
            min_num=x_num
    return min_num

def gcd_triple(x,y,z):
    return(gcd_dual(gcd_dual(x,y),z))

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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:
def gcd(i, j):
  if i % j != 0:
    return gcd(j, i % j)
  else:
    return j  

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

k = int(input())
total = 0

for i in range(1, k+1):
  for j in range(1, k+1):
    for t in range(1, k+1):
      g = gcd3(i, j, t)

      total += g

print(total)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
 
def aaa(*numbers):
    return reduce(fractions.gcd, numbers)
 
num = int(input())
list = []
for i in range(1,num+1):
    for j in range(1,num+1):
        for k in range(1,num+1):
            list.append(aaa(i,j,k))
print(sum(list))

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    '''
    code here
    '''
    import sys
    from functools import lru_cache
    sys.setrecursionlimit(10**3)
    K = int(input())

    @lru_cache(maxsize=10**3)
    def gcd(a, b):
        if b == 0:
            return a
        else:
            return gcd(b, a%b)


    def gcd3(a, b, c):
        temp = gcd(a,b)
        return gcd(temp, c)
    
    res = 0
    for k in range(1,K+1):
        for j in range(1,K+1):
            for i in range(1, K+1):
                res += gcd3(k, j, i)

    print(res)


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce


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


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

Submission status: Time Limit Exceeded

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

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


if __name__ == "__main__":

    k = int(input())
    ans = 0

    num = list(range(1, k+1))
    comb = tuple(itertools.product(num, repeat=3))


    for i in range(len(comb)):
        ans += gcd(comb[i])

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = math.gcd(a,l[i])
    return a

K = int(input())
list_A=[]
for i in range(K):
    for j in range(K):
        for k in range(K):
            list_A.append(gcdlist([i+1,j+1,k+1]))
print(sum(list_A))

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
from functools import reduce
def getN():
    return int(input())

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

def main():
    
    K = getN()

    result = 0

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

    return

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def gcd_a(a,b):
    if b == 0:
        return a
    else:
        return gcd_a(b,a%b)
def gcd(a,b,c):
    if gcd_a(a,b) == 1 or gcd_a(a,c) == 1 or gcd_a(b,c) == 1:
        return 1
    else:
        return gcd_a(gcd_a(a,b),c)
n = int(input())
x = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            x += gcd(i+1,j+1,k+1)
print(x)

Submission status: Time Limit Exceeded

Solution code:
import fractions
num = int(input())
sum = 0
for i in range(1, num+1):
  for j in range(1, num+1):
    for k in range(1, num+1):
      temp = fractions.gcd(i, j)
      sum += fractions.gcd(temp, k)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import fractions
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=ans+fractions.gcd(i,fractions.gcd(j,l))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import scipy as sp
from itertools import  combinations_with_replacement as com

def tri_gcd(a, b, c):
    return sp.gcd(a,  sp.gcd(b, c))


N = int(input())
ans = 0
duplication = 1
for a,b,c in com(range(1, N+1), 3):
    if len(set([a,b,c])) == 3:
        duplication = 6
    if len(set([a,b,c])) == 2:
        duplication = 3
    if len(set([a,b,c])) == 1:
        duplication = 1
    ans += duplication * tri_gcd(a, b, c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

import itertools
import math
from functools import reduce

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

lis = [i for i in range(1,K+1)]
S = [gcd_list(team) for team in itertools.product(lis, repeat = 3)]
print(sum(S))

Submission status: Time Limit Exceeded

Solution code:
y=int(input())
b=[[i,j,k]  for i in range(1,y+1) for j in range(1,y+1) for k in range(1,y+1) ]
c=[]
for l in range(y**3):
    import math
    a = b[l]
    ans = a[0]
    for i in range(1, 2):
        ans1 = math.gcd(ans, a[1])
        ans2 =math.gcd(ans,a[2])
        ans3 =math.gcd(ans1,ans2)
    c.append(ans3)
print(sum(c))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

a = int(input())
list1 = [np.gcd(np.gcd(x, y),z) for x in range(1, a+1) for y in range(1, a+1) for z in range(1, a+1)]
result = sum(list1)
      
print(result)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
import functools

K = int(input())

lista=list(range(1, (K+1)))
listb=list(range(1, (K+1)))
listc=list(range(1, (K+1)))

ans = [0]

#print(lista)
for pair in itertools.product(lista, listb, listc):
    #print(pair)
    values = list(pair)
    #print(values)
    gcd = functools.reduce(math.gcd, values)
    #print(gcd)
    ans.append(gcd)
print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
cnt = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            for i in range(1,min(a,b,c)+1):
                if a%i == b%i == c%i == 0:
                    tcnt = i
            cnt += tcnt
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

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(i, j, k)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

k = int(input().rstrip())

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

ans = 0
for a in range(1, k + 1):
    if a == 1:
        ans += k * k
    else:
       for b in range(1, k + 1):
            if b == 1:
               ans += k
            else:
                for c in range(1, k + 1):
                    if c == 1:
                        ans += 1
                    else:
                        ans += gcd([a, b, c])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy
k=int(input())
a=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1,k+1):
      if i<=j<=l:
        if i==j==l:
          a=a+i
        elif i==j and j!=l:
          a=a+3*numpy.gcd.reduce([i,l])
        elif i!=j and j==l:
          a=a+3*numpy.gcd.reduce([i,j])
        elif i!=j and j!=l:
          a=a+6*numpy.gcd.reduce([i,j,l])
      else:
        a=a+0
print(a)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

def get_gcd(a, b, c):
    min_ab = min(a, b)
    max_ab = max(a, b)
    amari = max_ab % min_ab
    if amari == 0:
        gcd1 = min_ab
    else:
        x = min_ab
        y = amari
        while y != 0:
            amari = x % y
            if amari == 0:
                gcd1 = y
                break
            x = y
            y = amari
    min_2 = min(c, gcd1)
    max_2 = max(c, gcd1)
    amari = max_2 % min_2
    if amari == 0:
        gcd2 = min_2
    else:
        x = min_2
        y = amari
        while y != 0:
            amari = x % y
            if amari == 0:
                gcd2 = y
                break
            x = y
            y = amari

    return gcd2




    return gcd


k = int(input())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools 
import math
from functools import reduce

num = int(input())
a_list = [i for i in range(1,num+1)]
comb_list = list(itertools.product(a_list, repeat=3))

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

print(sum([gcd_list(x) for x in comb_list]))

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
d=[]
for a in range(1,n+1):
    for b in range(1,n+1):
        for c in range(1,n+1):
            
            d.append(math.gcd(math.gcd(a, b),c))
print(sum(d))

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
def gcdtriple(a,b,c):
    return math.gcd(a, math.gcd(b,c))
ans = 0
for a in range(1, N+1):
    for b in range(1, N+1):
        for c in range(1, N+1):
            ans += gcdtriple(a,b,c)
print(ans)

Submission status: Time Limit Exceeded

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

print( sum )

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
x = range(1,n+1)
gcd = 0
for a in  x:
    for b in x:
        for c in x: 
            gcd += int(np.gcd.reduce([a, b, c]))
print(gcd)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
K = int(input())

ans = 0
for i in range(K):
    for j in range(K):
        for k in range(K):
            if i+1 == j+1 and j+1==k+1 and i+1 == k+1:
                ans += i+1
  
            elif i+1 == 1 or j+1 == 1 or k+1 == 1:
             
                ans +=1
            else:
               
                ans += gcd(i+1,j+1,k+1)
            #1-Kまで
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
result = 0
K = int(input())
for i in range(K):
  for j in range(K):
    for k in range(K):
      a = i+1
      b = j+1
      c = k+1
      num = gcd(a,b)
      num2 = gcd(num,c)
      result += num2
print(result)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K = int(input())
B = list()
a = int()
b = int()
c = int()
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            A = i,j,k
            B.append(A)
for i in range(len(B)):
    a = B[i][0]
    b = B[i][1]
    c = B[i][2]
    ans += gcd(a,b,c)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

def gcd_(a, b):
    if a < b:
        a, b = b, a
    while not a % b == 0:
        a, b = b, a % b
    return b

def gcd(a, b, c):
    length = len({a, b, c})
    if length == 1:
        return a
    elif length == 2:
        x, y = {a, b, c}
        return gcd_(x, y)
    else:
        x, y, z = {a, b, c}
        w = gcd_(x, y)
        return gcd_(w, z)

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

a=[0,0,0]
N = int(input())

wa=0
for i in range(1, N+1):
    a[0]=i
    for j in range(1,N+1):
        a[1]=j
        for k in range(1,N+1):
            a[2]=k
            
            wa=wa+gcd(a)

print(wa)

Submission status: Time Limit Exceeded

Solution code:
import fractions
K = int(input())
A = B = C = [i for i in range(1, K+1)]
 
cnt = 0
for a in A:
  for b in B:
    for c in C:
      ans = fractions.gcd(a, b)
      ans = fractions.gcd(ans, c)
      cnt += ans
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
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=s+gcd(i,j,k)
print(s)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

x = 0
n = int(input())+1

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce


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


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


K = int(input())

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

print(sums)