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
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, gcd
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# ここから書き始める
k = int(input())
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            # print("i =", i)
            # print("j =",j)
            # print("l =", l)
            ans += gcd_list([i, j, l])   
print(ans)

# n = int(input())
# s = input()
# r = []
# g = []
# b = []
# for i in range(n):
#     if s[i] == "R":
#         r.append(i)
#     elif s[i] == "G":
#         g.append(i)
#     else:
#         b.append(i)
# ans = 0
# for i in r:
#     for j in g:
#         for k in b:
#             x, y, z = sorted([i, j, k])
#             if y - x != z - y:
#                 ans += 1
# print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import lru_cache

@lru_cache(maxsize=100000)
def gcd_list(a, b, c):
    return gcd(gcd(a, b), c)

@lru_cache(maxsize=100000)
def gcd(x, y):
    return math.gcd(x, y)

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_list(a,b,c)
print(ans)

Submission status: Time Limit Exceeded

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

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):
            key = []
            key.append(math.gcd(x,math.gcd(y,z)))
            key.append(math.gcd(y,math.gcd(x,z)))
            key.append(math.gcd(z,math.gcd(y,x)))
            ans += max(key)
print(ans)

Submission status: Time Limit Exceeded

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

    return gcd(b, a % b)


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):
            tmp = gcd(j, k)
            sum += gcd(i, tmp)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import sys
import fractions, math
from functools import reduce

def gcd(i, j, k):
    return fractions.gcd(i, fractions.gcd(j, k))

def solve(K: int):
    counter = 0
    for i in range(1, K+1):
        for j in range(i, K+1):
            for k in range(j, K+1):
                c = gcd(i, j, k)
                if i == j and j == k:
                    counter += c
                elif i == j or j == k:
                    counter += 3 * c
                else:
                    counter += 6 * c
    print(counter)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

from functools import reduce
from math import gcd

#a = [12, 18, 24]
#b = reduce(gcd, a)


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):
            a = [i,j,k]
            b = reduce(gcd,a)
            cnt = cnt+b
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math

inputLine = input()
K = int(inputLine)

result = 0

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
import math

K  = int(input())
ans = 0
for a in range(K+1):
    for b in range(K+1):
        for c in range(K+1):
            if a*b*c !=0:
                s = math.gcd(math.gcd(a,b),c)
                ans = ans +s

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=0

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

print(ans)

Submission status: Time Limit Exceeded

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


a = int(input())
l = []
for i in range(1, a+1):
    for j in range(1, a+1):
        for k in range(1, a+1):
            l.append(gcd([i, j, k]))
print(sum(l))

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
N = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10 ** 6)

def input():
    return sys.stdin.readline()[:-1]

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def pgcd(a,b):
    if b==0:
        return a
    else:
        return pgcd(b,a%b)
def tgcd(a,b,c):
    return pgcd(a,pgcd(b,c))
def T(N):
    s=0
    for i in range(1,N+1):
        for j in range(1,N+1):
            for l in range(1,N+1):
                s+=tgcd(i,j,l)
    return s
N=int(input())
print(T(N))

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)

t = 0
k= int(input(''))+1
for l in range(1,k):
    for m in range(1,k):
        for n in range(1,k):
            t+= gcd_list([l,m,n])
#            print("{}/{}/{} -> {}".format(l,m,n,gcd(l,m,n)))

print(t)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

K = int(input())
gcd_v = {}
def gcd(numbers):
    tuple_n = tuple(sorted(numbers))
    try:
        return gcd_v[tuple_n]
    except:
        gcd_v[tuple_n] = reduce(math.gcd, numbers)
        return gcd_v[tuple_n]

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

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

k = int(input())
kl = list(range(1,k+1))
res = 0

for i in kl:
    for j in kl:
        for k in kl:
            res += gcd(i,j,k)

print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce 

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

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

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)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math


##get int
first_input = list(map(lambda x:int(x), input().split(" ")))
#second_input = list(map(lambda x:int(x), input().split(" ")))

##get float
#first_input = list(map(lambda x:float(x), input().split(" ")))
#second_input = list(map(lambda x:float(x), input().split(" ")))

##get string
#first_input = input().split(" ")

K = first_input[0]

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

print(gcd_sum)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
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(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())
s=0
import fractions
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            g=fractions.gcd(fractions.gcd(a,b),c)
            s+=g
print(s)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
import math
#import collections
#from collections import deque
#from bisect import bisect_left
K = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
s = 0
d = 0
e = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            d = math.gcd(c,b)
            e = math.gcd(a,d)
            s += e
print(s)

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
k=int(input())
r1=[]
r2=[]
for l in range(1,k+1):
    for m in range(1,k+1):
        r1.append(gcd(l,m))

for i in range(len(r1)):
    for j in range(1,k+1):
        r2.append(gcd(r1[i],j))

print(sum(r2))

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

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

N = II()
l = []
ans=0
for i in range(1, N+1):
    for j in range(1, N+1):
        for k in range(1, N+1):
            l1 = []
            l1.append(i)
            l1.append(j)
            l1.append(k)
            l.append(l1)

for L in l:
    ans += gcd_list(L)
print(ans)

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools as it
import fractions

K = int(input())

gcd_list = []
for i, j, k in it.product(range(1, K+1), range(1, K+1), range(1, K+1)):
    gcd_ = fractions.gcd(fractions.gcd(i, j), k)
    gcd_list.append(gcd_)
print(sum(gcd_list))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

k = int(input())

s = 0
for i in range(k):
    for j in range(k):
        for l in range(k):
            s += np.gcd.reduce([i+1,j+1,l+1])


print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
import copy
import sys
import fractions
# import numpy as np
# import statistics
import decimal
import heapq
import collections
import itertools
import bisect

# from operator import mul

sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputIntList():
    outputDataList = []
    inputData = input().split()
    outputDataList = [int(n) for n in inputData]

    return outputDataList


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

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

n = int(input())


ans = 0
tmp_gcd={}
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
from functools import reduce

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

K = int(input())
num = 0

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

print(num)

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):
            cnt = gcd(i, j, k)
            ans += cnt

print(ans)

Submission status: Time Limit Exceeded

Solution code:

import math

K = int(input())

gcd = []

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

print(sum(gcd))

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

import math



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

            d=0
print(s)

Submission status: Time Limit Exceeded

Solution code:
import math
def gcd(a, b, c):
    A = [a, b, c]
    ans = A[0]
    for i in range(1,len(A)):
        ans = math.gcd(ans, A[i])
    return int(ans)


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 += gcd(i, j, k)
print(total)

Submission status: Time Limit Exceeded

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

# when input is list type
def list_gcd(a):
    x=a[0]
    for i in range(1,len(a)):
        x=gcd(x,a[i])
    return x

ans=0
for i in range(k):
    ans+=i+1
    for j in range(i+1, k):
        ans+=3*list_gcd([i+1,j+1])
        ans+=3*list_gcd([i+1,j+1])
        for l in range(j+1, k):
            ans+=6*list_gcd([i+1,j+1,l+1])
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 = 0
a = list(range(1,k+1))
b = list(range(1,k+1))
c = list(range(1,k+1))

for i in a:
    for j in b:
        for k in c:
            ans += gcd(i,j,k)
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())
sum = 0
for x in range(1, k + 1):
	for y in range(1, k + 1):
		for z in range(1, k + 1):
			sum += gcd(x, y, z)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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 fractions
k=int(input())
s=0
for i in range(k):
    s+=i+1
for i in range(k):
    for j in range(i+1,k,1):
        s+=6*fractions.gcd(i+1,j+1)
for i in range(k):
    for j in range(i+1,k,1):
        for l in range(j+1,k,1):
            s+=6*(fractions.gcd(i+1,fractions.gcd(j+1,l+1)))
print(s)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce

def gcd1(*numbers):
  return reduce(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 += gcd1(a,b,c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K = int(input())
sumk = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            sumk += gcd_list([i,j,k])
print(sumk)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
K = int(input())
gcd_list = []
for k in range(1,K+1):
    a = k
    for l in range(1,K+1):
        b = l
        for m in range(1,K+1):
            c = m
            d = gcd(a,b)
            e = gcd(c,d)
            gcd_list.append(e)
print(sum(gcd_list))

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

Submission status: Time Limit Exceeded

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

res = sum([math.gcd(math.gcd(a+1, b+1), c+1) for a in range(K) for b in range(K) for c in range(K)])
print(res)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K = int(input())
S=0
for i in range(1,K+1):
	for h in range(1,K+1):
		for g in range(1,K+1):
			S+=gcd(g,h,i)

print(S)

Submission status: Time Limit Exceeded

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

import math
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 += math.gcd(math.gcd(i, j), l)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math
from functools import reduce

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

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

print(s)

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())

result = 0

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
import math
K=200
ans=0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            tempgcd=math.gcd(a,b)
            ans=ans+math.gcd(tempgcd,c)
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())

x = 0

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

print(x)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input().strip())

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

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())
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)

Submission status: Time Limit Exceeded

Solution code:
import math 

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

A=int(input())
ans=[]
for i in range(1,A+1):
    for j in range(1,A+1):
        for k in range(1,A+1):
            x=gcd(i,j,k)
            ans.append(x)
print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
import math 
k = int(input())
ans = 0 
dic = {}
for x in range(1, k+1):
  for y in range(1, k+1):
    dic[(x, y)] = math.gcd(x, y)

for x in range(1, k+1):
  for y in range(1, k+1):
    for z in range(1, k+1):
      ans += dic[(x, dic[(y, z)])]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import *
from heapq import *
from itertools import *
from fractions import gcd

from decimal import *
import copy
from bisect import *
import time
import sys
import math
input=lambda :sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
K=int(input())
#A,B=map(int,input().split())
#A=list(map(int,input().split()))
z=0
for a in range(1,K+1):
    for b in range(1,K+1):
        d=gcd(a,b)
        if d==1:
            z+=K
        else:
            for c in range(1,K+1):
                z+=gcd(c,d)
print(z)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
from functools import reduce

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

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

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())
res = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            res = res + gcd_list([i, j, k])
print(res)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from math import gcd
from functools import reduce

def gcd_list(numlist):
    return reduce(gcd, numlist)

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

    s = 0

    for a in range(1, K+1):
        for b in range(1, K+1):
            for c in range(1, K+1):
                s += gcd_list([a, b, c])
    
    print(s)



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

Submission status: Time Limit Exceeded

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

K=int(input())
result=0
for i in range(K):
	for j in range(K):
		for k in range(K):
			result+=reduce(math.gcd,[i+1,j+1,k+1])

print(result)

Submission status: Time Limit Exceeded

Solution code:
#C
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
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)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd,numbers)
K=int(input())
a=1
b=1
c=1
sum_abc=0
if 1<=K<=200:
    for c in range(1,K+1):
        for b in range(1,K+1):
            for a in range(1,K+1):
                sum_abc+=gcd(a,b,c)
                a+=1
            b+=1
        c+=1
    print(sum_abc)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
s = 0
import math
from functools import reduce
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      s += reduce(math.gcd, [a,b,c])
print(s)

Submission status: Time Limit Exceeded

Solution code:
import math
import functools

k = int(input())
k = k+1
ans = 0
for i in range(1,k):
	for j in range(1,k):
		for kk in range(1,k):
			ans += functools.reduce(math.gcd, [i,j,kk])
print(ans)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

import math
from functools import reduce

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

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


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

Submission status: Time Limit Exceeded

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

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)
cnt=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):
            cnt+=gcd(x,y,z)
    
print(cnt)