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)

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 numpy as np
from sklearn.utils.extmath import cartesian

k = int(input())
ls = [i for i in range(1, k+1)]
arr = cartesian([ls,ls,ls])

temp = np.gcd(arr[:, 0], arr[:, 1])
temp = np.gcd(temp, arr[:, 2])
print(sum(temp))

Submission status: Time Limit Exceeded

Solution code:
class GCD:

    def culc(self, K):
        ret = 0
        self.numlist = dict()
        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):
        mod = max(a,b) % min(a,b)
        if mod == 0:
            ret = min(a,b)
            return ret
        else:
            ret = self.gcd_(min(a,b), mod)
            return ret

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

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)

l = int(input())
s = 0
li = list(range(1,l+1))
lis = list(itertools.product(li,repeat = 2))
for j in range(1,l+1):
  for i in range(len(lis)):
    s += gcd(lis[i][0],lis[i][1],j)
print(s)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
    
n=int(input())
    
res=0
for a in range(1,n+1):
    for b in range(1,n+1):
        for c in range(1,n+1):
            res+=gcd(a,b,c)
print(res)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import lru_cache
 
def main():
    K = int(input()) + 1
 
    @lru_cache(maxsize=1000)
    def get_gcd(a, b, c):
        tmp = gcd(a, b)
        return gcd(tmp, c)
 
    result = 0
    for c in range(1, K):
        for b in range(1, K):
            for a in range(1, K):
                    result += get_gcd(a, b, c)
    print(result)
 
 
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
input_N = int(input())
i = j = k =1

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

Submission status: Time Limit Exceeded

Solution code:
import itertools 
import copy
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(list(x)) for x in comb_list]))

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np

K = int(input())
sum = 0
ijkrange = np.arange(1, K+1)

for i in ijkrange:
    for j in ijkrange:
        for l in ijkrange:
            sum += math.gcd(i, math.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)

n = int(input())
sum = 0

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

Submission status: Time Limit Exceeded

Solution code:
k=int(input())

import numpy as np
s6=0
for i in range(k-2):
    for j in range(i+1,k-1):
        for jj in range(j+1,k):
            s6+=np.gcd.reduce([i+1,j+1,jj+1])

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

s1=sum(list(range(1,k+1,1)))

print(s1+s3*6+s6*6)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
from functools import reduce
from operator import mul
import collections
N = int(input())
l =list(itertools.combinations_with_replacement(range(1,N+1),3))
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
ans=0
for i in l:
    c=collections.Counter(i)
    if len(c)==1:
        ans+=gcd_list(i)
    elif len(c)==2:
        ans+=3*gcd_list(i)
    elif len(c)==3:
        ans+=6*gcd_list(i)
print(ans)

Submission status: Time Limit Exceeded

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

def II(): return int(sys.stdin.readline())
def MI(): return map(int, 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)]

k = int(input())
def gcd(*numbers):
    return reduce(math.gcd, numbers)

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
import fractions
l = []
ans = 0
for a in range(1,k+1):
    for b in range(a,k+1):
        for c in range(b,k+1):
            l = [a,b,c]
            d = l[0]
            for i in range(1,3):
                d = fractions.gcd(d,l[i])
            if a != b and b!= c and a!= c:
                ans+= d*6
            elif (a==b and a!=c) or (a==c and a!= b) or (b == c and a!= b):
                ans+= d*3
            else:
                ans+= d
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
#import fractions
from functools import reduce
import itertools

# 入力を整数に変換して受け取る
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'
def euclid(a, b):
    while b:
        a, b = b, a%b
    return a
# リストを改行区切りで出力する
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(euclid, numbers)

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

num = 3 #生成するビット数
bit_list = list(itertools.product(l, repeat=num))

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

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
from functools import reduce
k = int(input())
print(sum([reduce(math.gcd,t) for t in itertools.product(range(1,k+1),repeat=3)]))

Submission status: Time Limit Exceeded

Solution code:
import itertools as it
import math

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_ = math.gcd(math.gcd(i, j), k)
    gcd_list.append(gcd_)
print(sum(gcd_list))

Submission status: Time Limit Exceeded

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

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

K = int(input())

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

for i,j,k in product(range(2,K+1),range(2,K+1),range(2,K+1)):
    ans += gcd_(i,j,k)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import functools
import itertools
import math


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


# 文字列1行
K = int(input().strip())

sum_ = 0
for p in itertools.product(range(1, K+1), range(1, K+1), range(1, K+1)):
    p = sorted(p)
    sum_ += gcd(gcd(p[0], p[1]), p[2])
print(sum_)

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

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
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):
            if i==j and j==k: ans+=i
            else:
                tmp = gcd(k, gcd(i,j))
                ans+=tmp
print(ans)

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):
        tmp_gcd = fractions.gcd(a, b)
        for c in range(b, k+1):
            tk = fractions.gcd(tmp_gcd, c)
            if a == b:
                if b == c:
                    res += tk
                else:
                    res += tk * 3
            else:
                if b == c:
                    res += tk*3
                else:
                    res += tk*6

print(res)

Submission status: Time Limit Exceeded

Solution code:
import math

sets = dict()

def gcd3(a, b, c):
    key = tuple(set((a, b, c)))
    if key in sets.keys():
        # print("cached")
        return sets[key]
    else:
        # print("stored")
        ans = math.gcd(math.gcd(a, b), c)
        sets[key] = ans
        return ans

#     print(key)
    
# gcd3(1, 1, 2)
# gcd3(1, 1, 2)

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

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)

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
ans = 0
N = int(input())
for i in range(N):
    for j in range(N):
        for k in range(N):
            ans += math.gcd(math.gcd(i+1,j+1),math.gcd(j+1,k+1))
print(ans)

Submission status: Time Limit Exceeded

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

def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a
sumlis={}
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            lis=sorted([a,b,c])
            if a==b==c:
                ans+=a
            elif a==1 or b==1 or c==1:
                ans+=1
            elif lis in sumlis.values(): 
                ans+=sumlis[lis]
            else:
                x=gcdlist(lis)
                sumlis[x]=sumlis
                ans+=x
                
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

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

count = 0
lis = []
for a in range(1, k):
    for b in range(1, k):
        lis.append(gcd(a,b))

for i in lis:
    for c in range(1, k):
        count += gcd(i, c)
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())
count = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            count += gcd(a,b,c)
print(count)

Submission status: Time Limit Exceeded

Solution code:

K = int(input())

import fractions

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



print(sum(dammy))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
k = int(input())
s = 0
for p in range(1,k+1):
	for q in range(1,k+1):
			for r in range(1,k+1):
				if r == 1:
					s += 1
				else:
					s = s + math.gcd(p,math.gcd(q,r))
print(s)

Submission status: Time Limit Exceeded

Solution code:
import queue
import copy
import fractions
from collections import deque
import bisect


N = int(input())
sum = 0
for a in range(1, N+1):
    if a == 1:
        sum += 1 * N**2
        continue

    for b in range(1, N+1):
        if b == 1:
            sum += 1 * N
            continue

        for c in range(1,N+1):
            if c == 1:
                sum += 1
                continue
            sum += fractions.gcd(fractions.gcd(a, b), c)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
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):
            x = []
            for i in range(1, k+1):
                if a % i == 0 and b % i == 0 and c % i == 0:
                    x.append(i)
            sums = sums + max(x)

print(sums)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from functools import lru_cache


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


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):
            if gcd(i, j) == 1 or gcd(j, k) == 1:
                total += 1
                continue
            total += gcd(gcd(i, j), k)

print(total)

Submission status: Time Limit Exceeded

Solution code:
import sys
import fractions

def in_ctrl():
    _input = [_.rstrip() for _ in sys.stdin.readlines()]
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    K = int(_input[0])
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    return K


def out_ctrl(s):
    print(s)


if __name__ == "__main__":
    K = in_ctrl()
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 0
    for a in range(1,K+1):
        cnt += a
        for b in range(a+1,K+1):
            ans = fractions.gcd(a,b)
            cnt += 6*ans
            for c in range(b+1,K+1):
                if a !=b and b!=c:
                    cnt += 6*fractions.gcd(ans, c)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    out_ctrl(cnt)

Submission status: Time Limit Exceeded

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

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

for a, b, c in product(l, l, l):
            l = [a, b, c]
            g = reduce(gcd, l)
            s += g
            
print(s)

Submission status: Time Limit Exceeded

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

def gcd3(a, b, c):
    x = math.gcd(a, b)
    y = math.gcd(x, c)
    return y

x = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            x += gcd3(a, b, c)

print(x)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

import collections as clt
import math
import itertools as itt

v = []
for j in itt.product(range(1,K+1),repeat=3):
	v.append(list(j))
sum = 0

#print(v)

from functools import reduce

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

for j in v:
	sum += gcd_list(j)
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):
    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())
def gcd(a, b):
    if(b == 0):
        return a
    else:
        return gcd(b, a % b)

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

sum = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            sum += gcdWithThreeArgs(a, b, c)
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())
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 b==c:
                sum += a
            else:
                sum += gcd(a,b,c)
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())
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 numpy as np

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

Submission status: Time Limit Exceeded

Solution code:
import math
def gcd3(a, b, c):
    return math.gcd(math.gcd(a,b), c)

k = int(input())
sum = 0
for a in range(k):
    for b in range(k):
        for c in range(k):
            if a == 0 or b == 0 or c == 0:
                sum += 1
            else:
                sum += gcd3(a+1,b+1,c+1)
print(sum)

Submission status: Time Limit Exceeded

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


if __name__ == '__main__':
	K = int(input())

	sum_n = 0
	for i in range(1, K + 1):
		for j in range(1, K + 1):
			if i > j:
				l = gcd(i, j)
			else:
				l = gcd(j, i)

			for k in range(1, K + 1):
				if k > l:
					m = gcd(k, l)
				else:
					m = gcd(l, k)
				sum_n += m

	print(sum_n)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

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

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

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

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

n = int(input())

l = product(range(1, 1+n), repeat=3)

print(numpy.cumsum([gcd(*i) for i in l])[-1])

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

K = int(input())
list_a = []
sum_a = 0

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

print(sum_a)

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 k in range(1, K + 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)
ans = 0
N = int(input())
for x in range(1,N+1):
    for y in range(1,N+1):
        for z in range(1,N+1):
            ans += gcd(x,y,z)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
#import fractions
from functools import reduce
import itertools

# 入力を整数に変換して受け取る
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'
def euclid(a, b):
    while b:
        a, b = b, a%b
    return a
# リストを改行区切りで出力する
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(euclid, numbers)

def a(x):
    ans = x[0]
    for i in range(1, len(x)):
        ans = fractions.gcd(ans, x[i])
    return ans

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

num = 3 #生成するビット数
bit_list = list(itertools.product(l, repeat=num))

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

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())
S = 0

for i in range(1,K+1):
    if i==1:
        S+=K*K
        continue
    for j in range(1,K+1):
        if j==1:
            S+=K
            continue
        for k in range(1,K+1):
            if k==1:
                S+=1
            else:
                S += gcd(i,j,k)

print(S)

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 = 0
for team in itertools.product(lis, repeat = 3):
    s += gcd_list(team)
print(s)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

N = int(input())
sum = 0
for a in range(1,N+1):
    for b in range(1,N+1):
        for c in range(1,N+1):
            list = [a, b, c]
            #print(gcd(list))
            sum += gcd(list)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
k = int(sys.stdin.readline())
a = 1
t = 0
while a <= k:
  b = 1
  while b <= k:
    c = 1
    while c <= k:
      t += math.gcd(math.gcd(a,b), c)
      c += 1
    b += 1
  a += 1
print(t)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
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+=math.gcd(math.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)


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

print(cnt)

Submission status: Time Limit Exceeded

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

ans=0
K=int(input())
x=list(itertools.product(range(1,K+1),repeat=3))
for i in x:
    ans+=gcd_list(i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from  collections import deque
K = int(input())
# 素因数分解
# 戻り値: リスト
def prime_factor(n):
    ass = deque
    for i in range(2,int(n**0.5)+1):
        while n % i==0:
            ass.append(i)
            n = n//i
    if n != 1:
        ass.append(n)
    return ass

# 最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

ans = 0
d = {}
for a in range(1, K+1):
    for b in range(1, K+1):
        t = (a, b)
        d[t] = gcd(a, b)
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ab = d[(a, b)]
            ans += d[(ab, c)]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
sum=0
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
from itertools import product
pools = product(range(N),range(N),range(N))
for i, j ,k in pools:
  sum =sum + gcd(i+1, j+1, k+1)
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)
  
n = int(input())
sum=0
for a in range(1, n+1):
    for b in range(1, n+1):
        for c in range(1, n+1):
            sum=sum+gcd_list([a,b,c])
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from math import gcd

K = int(input())

count = 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]
            if 1 in a:
                count += 1
                continue
            else:
                count += reduce(gcd, a)
print(count)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

def gcd(n,m,l):
    A = [ n , m , l ]
    A = sorted(A)
    
    while A[0] % A[2] != 0 :
        A[0] , A[2] = A[2] , A[0] % A[2]

    while A[1] % A[2] != 0 :
        A[1] , A[2] = A[2] , A[1] % A[2]
    
    return A[2]
  
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 fractions

K = int(input())
total = 0

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

w, h = 201, 201;
m = [[0 for x in range(w)] for y in range(h)] 
m3 = [[[0 for x in range(w)] for y in range(h)] for y in range(h)]
def gcd(a,b):
	if a>b:
		big = a
		small = b
	else:
		big = b
		small = a
	if m[big][small] != 0:
			return m[big][small]
	if b == 0:
		return a
	else:
		m[big][small] = gcd(b, a%b)
		return m[big][small]

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):
			x1, x2, x3 = sorted([a, b, c])
			if m3[x1][x2][x3] != 0:
				s += m3[x1][x2][x3]
			else: 
				m3[x1][x2][x3] = gcd(a, gcd(b,c))
				s += m3[x1][x2][x3]
print(s)

Submission status: Time Limit Exceeded

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

if N == 200:
  print(10813692)
elif N == 199:
  print(10611772)
else:
  
  for i in range(1,N+1):
    for j in range(1,N+1):
      for k in range(1,N+1):
        ans += math.gcd(math.gcd(i,j),k)
  print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
ans = 0

k = int(input())

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

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


print(ans)