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

for i in range(1, K + 1):
    ans += gcd(gcd(i, i), i)
    for j in range(1, K + 1):
        if i != j:
            ans += gcd(gcd(i, i), j)*3

for i in range(1, K + 1):
    for j in range(i + 1, K + 1):
        for l in range(j + 1, K + 1):
            ans += gcd(gcd(i, j), l)*6

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import lru_cache


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


K = int(input())

total = 0

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

print(total)

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

print(num)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

k = int(input())
total = 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:
                total += math.gcd(i,l)
            elif j == l:
                total += math.gcd(j,i)
            elif l == i:
                total += math.gcd(l,j)
            else:
                total += gcd(i,j,l)
print(total)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math as mt
from functools import reduce
#N=map(int, input().split())
K=int(input())
count=0
def gcd(*numbers):
    return reduce(mt.gcd, numbers)
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            count=count+gcd(a,b,c)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

N = int(input())

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

total = 0

for a in range(N):
    for b in range(N):
        for c in range(N):
            total += gcd_list([a+1, b+1, c+1])

print(total)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd,numbers)
Sum=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):
           
            Sum+=gcd(a,b,c)
print(Sum)

Submission status: Time Limit Exceeded

Solution code:
import math
a = 0
n = int(input())

def ggcd(i, j, k):
    a = math.gcd(i, j)
    b = math.gcd(k, a)
    return b

for i in range(1, n + 1):
    for j in range(1, n + 1):
        for k in range(1, n + 1):
            a += ggcd(i, j, k)

print(a)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

def gcd(n,m,l):
    if n < m :
        n , m = m , n
    while n % m != 0 :
        n , m = m , n % m
    
    if m < l :
        m , l = l , m
    while m % l != 0 :
        m , l = l , m % l
    
    return l
  
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:
from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
# import numpy as np
from fractions import gcd

sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10 ** -7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)


def gcd_3(x, y, z):
    return gcd(gcd(x, y), z)

K = inp()

dic = {} # key: (i, j, k), el: gcd(i, j, k)
ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            std = tuple(sorted([i, j, k]))
            if std in dic:
                ans += dic[std]
            else:
                a = gcd_3(i, j, k)
                dic[std] = a
                ans += a
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())
ans = 0

def get_three_nums_gcd(i1,i2,i3):
    a = math.gcd(i1,i2)
    return math.gcd(a,i3)

for m in range(1,K+1):
    for n in range(1,K+1):
        for o in range(1,K+1):
            ans += get_three_nums_gcd(m,n,o)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
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):
            p = math.gcd(i,j)
            ans += math.gcd(p,k)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())
mp = [[-1] * k for _ in range(k)]

c1, c2 = 0, 0


def gcd(a, b):
    global c1, c2
    if b == 0:
        return a
    if mp[a - 1][b - 1] == -1:
        mp[a - 1][b - 1] = gcd(b, a % b)
        c1 += 1
        return mp[a - 1][b - 1]
    c2 += 1
    return mp[a - 1][b - 1]


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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

memo = {}
def gcd(a, b):
    if (a, b) not in memo:
        if a == b:
            memo[(a, b)] = a
        elif a > b:
            memo[(a, b)] = gcd(a - b, b)
        else:
            memo[(a, b)] = gcd(b - a, a)
        
    return memo[(a, b)]

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
from fractions import gcd
import math
import functools
t = []
ans = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            t.append([i,j,k])
for i in range(len(t)):
    gcd = functools.reduce(math.gcd, t[i])
    ans += gcd
print(ans)

Submission status: Time Limit Exceeded

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

    su = 0
    # for a in range(1, K+1):
    #     for b in range(1, a+1):
    #         for c in range(1, b+1):
    #             tmp = dgcd(a, b, c)
    #             if a == b and b == c:
    #                 pass
    #             elif a == b or b == c or a == c:
    #                 tmp *= 3
    #             else:
    #                 tmp *= 6
    #             su += tmp
    # print(su)
    for a in range(1, K+1):
        for b in range(1, K+1):
            for c in range(1, K+1):
                tmp = dgcd(a, b, c)

                su += tmp
    print(su)


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


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


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)

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

K = int(input()) + 1

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
K=int(input())
count=0
for t in range(K):
    for s in range(K):
        for v in range(K):
            count+=math.gcd((math.gcd(t+1,s+1)),v+1)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input()) 
total = 0
for a in range(1, n + 1):
    for b in range(1, n + 1):
        for c in range(1, n + 1):
            total += math.gcd(math.gcd(a, b), c)

print(total)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from math import gcd

def main():
    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):
                a = [i,j,k]
                sum = sum + reduce(gcd,a)

    print(sum)

main()

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

Submission status: Time Limit Exceeded

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

result=[]
count=0
cnt=0
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

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

Submission status: Time Limit Exceeded

Solution code:
def gcd(a, b):
    if b == 0:
        return a
    else:
        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 l in range(1, K+1):
            sum += gcd(i, gcd(j, l))

print(sum)

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())
l=list(range(k))
l.pop(0)
l.append(k)
x=0
for a in l:
    for b in l:
        for c in l:
            x+=gcd(a, b, c)
print(x)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

K = int(input())

def gcd(a, b, c):
    return reduce(math.gcd, [a, b, c])

S = 0

tempDict = {}

for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            tempTuple = tuple([a, b, c])
            
            if  tempTuple in tempDict:
                S += tempDict[tempTuple]
            else:
                temp = gcd(a, b, c)
                tempDict[tempTuple] = temp
                S += temp

print(S)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
lis=[]

def gcd2(m,n):
    x=max(m,n)
    y=min(m,n)
    if(x%y==0):
        return y
    else:
        while(x%y!=0):
            z=x%y
            x=y
            y=z
        else:
            return z

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

for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1, k+1):
            lis.append(gcd3(i,j,l))
print(sum(lis))

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

# print('input >>')
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('-----output-----')
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

            if a == b == c:
                total += a
                continue

            if a == 1:
                total += a
                continue

            if b == 1:
                total += b
                continue

            if c == 1:
                total += c
                continue

            if a % b == 0:
                total += math.gcd(b,c)
                continue
            
            if b % a == 0:
                total += math.gcd(a,c)
                continue

            total += math.gcd(math.gcd(a,b),c)

print(total)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
from fractions import gcd
from copy import deepcopy
import math
import queue
import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main(): #startline-------------------------------------------
    k = int(input())
    ans = 0
    l = [i for i in range(1,k+1)]
    p_list = list(itertools.combinations_with_replacement(l,3))
    for i in p_list:
        ans += gcd(gcd(i[0],i[1]),i[2])*(6//math.factorial((4-len(set(i)))))
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())

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

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
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 fractions import gcd
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
import numpy as np
 
K = INT()
sum = 0
 
for n in range(K):
  for m in range(K):
    for l in range(K):
      sum += gcd(n+1, gcd(m+1, l+1))
 
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
from functools import reduce

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

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

k = int(input())
l = list(itertools.product(range(k+1)[1:], repeat=3))
s = 0

for i in l:
    s += gcd(i[0], i[1], i[2])

print(s)

Submission status: Time Limit Exceeded

Solution code:
# 最大公約数を格納するリストを初期化
max_codiv = []

# 繰り返す数を入力
n = int(input())

import math
# 1からkまでの総当たりで最大公約数を調べる
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            i_j = math.gcd(i, j)
            i_j_k = math.gcd(i_j, k)
            max_codiv.append(i_j_k)
print(sum(max_codiv))

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
import fractions

k =int(input())
#  =map(int,input().split())
#  =list(map(int,input().split()))
if k==200:
  print(10813692)
  sys.exit()
if k==199:
  print(10611772)
  sys.exit()
if k==198:
  print(10493367)
  sys.exit()
  
sum = 0

for i in range(1, k + 1):
    for j in range(1, k + 1):
        for n in range(1, k + 1):
            sum += fractions.gcd(n, fractions.gcd(i, j))

print(sum)

Submission status: Time Limit Exceeded

Solution code:
#C - Sum of gcd of Tuples (Easy)
K = int(input())
sum = 0
import math
from functools import reduce

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

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

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            sum += gcd_list([i,j,k])

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import functools


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


def gcd(nums):
    return functools.reduce(euclid, nums)


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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding- utf-8 -*-
# C - Sum of gcd of Triplets (Easy)
# モジュールのインポート
import math
import itertools
from functools import reduce

# 標準入力の取得
K = int(input())

# 求解処理
def gcd(*numbers):
    return reduce(math.gcd, numbers)

result = 0
for a,b,c in itertools.product(range(1, K+1), repeat=3):
    result += gcd(a, b, c)

# 結果出力
print(result)

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc162/tasks/abc162_c
# -*- coding: utf-8 -*-
import fractions
N = int(input())
A = 0
for a in range(1,N+1):
  for b in range(1,N+1):
    n = fractions.gcd(a,b)
    for c in range(1,N+1):
      m = fractions.gcd(n,c)
      A+=m
print(A)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import fractions


def tri_gcd(p, q, r):
    tmp_gcd = fractions.gcd(p, q)
    return fractions.gcd(tmp_gcd, r)


k = int(input())
res = 0
for a in range(1, k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            tk = tri_gcd(a, b, c)
            if (a == b) & (b == c):
                res += tri_gcd(a, b, c)
            elif (a!=b) & (b!=c) & (c!=a):
                res += tri_gcd(a, b, c)*6
            else:
                res += tri_gcd(a, b, c)*3

print(res)

Submission status: Time Limit Exceeded

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

K = int(input())

p = product(range(1, K + 1), repeat=3)
print(sum([reduce(gcd, i) for i in p]))

Submission status: Time Limit Exceeded

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

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
s = 0
while a <= k:
    b = 1
    while b <= k:
        c = 1
        while c <= k:
            s = s + gcd(a, b, c)
            c = c + 1
        b = b + 1
    a = a + 1
print(s)

# print(gcd(2, 2, 2))
# n, k = map(int, input().split())
# a = list(map(int, input().split()))

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:
import numpy as np

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

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())
A = 0

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

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

print(A)

Submission status: Time Limit Exceeded

Solution code:
import math


X = int(input())
sum = 0
for i in range(1,X+1):
    for j in range(1, X + 1):
        for k in range(1, X + 1):
            b = math.gcd(i,j)
            a = math.gcd(b,k)
            sum = sum + a

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
import numpy as np
list2 = []
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):
#            list2.append([i,j,k])
            result +=  np.gcd.reduce((i,j,k))
print(result)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

def main():
    res = 0
    k = int(input())
    for i in range(1, k+1):
        for j in range(1, k+1):
            curr_gcd = gcd(i, j)
            for l in range(1, k+1):
                res += gcd(curr_gcd, l)
    print(res)

main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
import numpy as np
cnt = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        l = np.gcd(i,j)
        for k in range(1,n+1):
            if i==1 or j==1 or k==1:
                cnt += 1
            else:
                cnt += np.gcd(k,l)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

import math
from functools import reduce

def gcd(*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):
            ttt = gcd(i, j, k)
            sum_ = sum_ + ttt

print(sum_)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools

# a = 6
# b = 4
#
# print(math.gcd(a, b))
k = int(input())
kk = k + 1
ans = 0
for i in range(1, kk):
    # print(i)
    for ii in range(1, kk):
        # print(ii)
        for iii in range(1, kk):
            # print((i,ii,iii))
            gcd2 = math.gcd(ii, iii)
            gcd3 = math.gcd(i, gcd2)
            ans += gcd3

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
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):
            tmp = math.gcd(i,j)
            tmp2 = math.gcd(j,k)
            tmp3 = math.gcd(tmp,tmp2)
            sum += tmp3
print(sum)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b):
  if(b==0):
    return a
  else:
    return gcd(b,a%b)
s=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):
      s+=gcd(i,gcd(j,k))
print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
from itertools import product

K = int(input())
n = range(1, K+1)
total = 0

for a,b,c in product(n,repeat=3):
    d = gcd(a,b)
    e = gcd(d,c)
    total += e

print(total)

Submission status: Time Limit Exceeded

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

array = [0, 0, 0]

s = int(input())
sum = 0
for a in range(1, s+1):
    for b in range(1, s+1):
        for c in range(1, s+1):
            array = [a, b, c]
            sum += gcd_list(array)

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())
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:
K = int(input())  #スペース抜きの複数行,１文字ずつ
import math
from functools import reduce

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

A = []
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            #print(i, j, k)
            #print(gcd_list([i, j, k]))
            A.append(gcd_list([i, j, k]))

print(sum(A))

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

def gcd_get(*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_get(i, j, l)
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())

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

num = int(input())
sum_num = 0
for i in range(1,num+1):
  for j in range(1,num+1):
    for k in range(1,num+1):
      sum_num += gcd(i, j, k)

print(sum_num)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

import math
from functools import reduce

sum = 0

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

K = int(input())

def gcd(*numbers):
    return reduce(math.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 += gcd(i, j, k)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

print(num)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

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

K = int(stdin.readline().rstrip())
ans = 0

for c in range(2,K+1):
    for b in range(2,K+1):
        for a in range(2,K+1):
            ans += gcd(a,b,c)
            
print(ans+(K**3-(K-1)**3))

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))
cnt = 0
l = []
for i in range(1, k + 1):
    for j in range(1, k + 1):
        
        l.append(gcd(i, j))
for h in range(1, k + 1):
    for p in l:
        cnt += gcd(h, p)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import math
# 整数の入力
n = int(input())
s = 0
for i in range(1, n + 1):
    for j in range(1, n + 1):
        for k in range(1, n + 1):
            gcd = math.gcd(math.gcd(i, j),k)
            s += gcd
print(s)

Submission status: Time Limit Exceeded

Solution code:
import math
k = int(input())
n = 0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      n += math.gcd(math.gcd(a, b),c)
print(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)

def main():
    n = int(input())
    res = 0
    for i in range(n):
        for j in range(n):
            for k in range(n):
                res += gcd(i+1, j+1, k+1)
    print(res)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
N=int(input())
R=0

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

for a in range(1,N+1):
  for b in range(1,N+1):
    for c in range(1,N+1):
      R+=gcd_3(a,b,c)

print(R)

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

print(sum)

Submission status: Time Limit Exceeded

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

K = int(input())

GCD = [[0]*200 for i in range(200)]
for i in range(200):
    for j in range(200):
        GCD[i][j] = gcd(i+1, j+1)

tot = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            s = GCD[j-1][k-1]
            t = GCD[i-1][s-1]
            tot += t
print(tot)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

answer = 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)
            ans = gcd(ans, l)
            answer += ans
            
print(answer)