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:
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)

K = int(input())
q = []
r = []
for i in range(1,K+1):
    for j in range(1,K+1):
        q.append(gcd(i,j))
for i in range(1,K+1):
    for j in q:
        r.append(gcd(i,j))
print(sum(r))

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 l in range(k):
    for m in range(k):
        for n in range(k):
            Sum += gcd(l+1, m+1, n+1)
            
print(Sum)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
import math
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(i,math.gcd(j,l))
print(ans)

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(i, K + 1):
        for k in range(j, K + 1):
            a = gcd_3(i, j, k)
            if i == j == k:
                ans += a
            elif i == j or j == k:
                ans += a * 3
            else:
                ans += a * 3 * 2
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
gcdlis=[]
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 lis in sumlis: 
                ans+=gcdlis[sumlis.index(lis)]
                
            else:
                sumlis.append(lis)
                x=gcdlist(lis)
                gcdlis.append(x)
                ans+=x
                
print(ans)

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

print(total)

Submission status: Time Limit Exceeded

Solution code:
def find_gcd(x, y):

    while(y):
        x, y = y, x%y

    return x

nums = int(input())
result = 0

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce


K = int(input())
ans = 0

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

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

n = int(input())

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

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

print(sum([gcd(*i) for i in l]))

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
K=int(input())
A=[]
for i in range(1,K+1):
  A.append(i)

 
ans=[]
for a,b,c in (itertools.product(A,A,A)):
    x=math.gcd(a,b)
    y=math.gcd(x,c)
    ans.append(y)
    
 
    
print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
import math

line = input()
num = int(line)
total = 0

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

Submission status: Time Limit Exceeded

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

i = 1
j = 1
k = 1
sum = 0

for i in range(n):
    for j in range(n):
        for k in range(n):
            sum += math.gcd(math.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())
sum1 = 0

for i in range(1,N + 1,1):
    for j in range(1,N + 1,1):
        for k in range(1,N + 1,1):
            #print("gcd(",i,",",j,",",k,")")
            sum1 = sum1 + gcd(i,j,k)


print(sum1)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from math import gcd

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

Submission status: Time Limit Exceeded

Solution code:
import math

import sys
k = sys.stdin.readline()
k = int(k)
sum = 0
for x in range(1,k+1):
    for y in range(1,k+1):
        for z in range(1,k+1):
            sum = sum +math.gcd(math.gcd(x, y), math.gcd(y, z))

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())
ans = 0
t = 0
import math
for i in range(1,n+1):
  for j in range(1,n+1):
#    t = math.gcd(i,j)
    for k in range(1,n+1):
      ans += gcd_list([i,j,k])
print(ans)

Submission status: Time Limit Exceeded

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

k = int(input())

result = 0

for x in range(1, k+1):
    for y in range(1, k+1):
        for z in range(1, k+1):
            result += gcd(x, gcd(y, z))

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

import sys
K=input()
K=int(K)
L=[]
a=1
b=1
c=1
for i in range(K):
    for j in range(K):
        for m in range(K):
            L.append(gcd(a,b,c))
            c=c+1
        c=1
        b=b+1
    b=1
    c=1
    a=a+1

S=sum(L)
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(numbers):
    return reduce(math.gcd, numbers)
K=int(input())
S=[]
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            S.append(gcd(i,j,k))
print(sum(S))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

def gcd(a,b,c):
    d = math.gcd(a,b)
    return math.gcd(d,c)
cnt =0
L =[]
K = int(input())
for i in range(1,K+1):
    for m in range(1,K+1):
        for u in range(1,K+1):
            L.append(gcd(i,m,u))
print(sum(L))

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

Submission status: Time Limit Exceeded

Solution code:
import fractions

k=int(input())
tot=0

for i in range(1,k+1):
    for j in range(1,k+1):
        for m in range(1,k+1):
            ans=i
            ans=fractions.gcd(ans,j)
            ans=fractions.gcd(ans,m)
            tot+=ans
print(tot)

Submission status: Time Limit Exceeded

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

def gcd2(a, b, c):
	aa = gcd(a,b)
	return gcd(aa,c)

n=int(input())
N=list(range(1,n+1))
print(sum([gcd2(a,b,c) for a,b,c in [[a, b, c] for a in N for b in N for c in N]]))

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):
            tmp = math.gcd(i, j)
            sum_ += math.gcd(tmp, 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)

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:
from math import gcd
import sys
si = sys.stdin.readline
d = {}


def main():
    k = int(si())
    ans = 0
    for p in range(1, k+1):
        for q in range(1, k+1):
            for r in range(1, k+1):
                if (q, r) in d:
                    t1 = d[(q, r)]
                elif (r, q) in d:
                    t1 = d[(r, q)]
                else:
                    t1 = gcd(q, r)
                    d[(q, r)] = t1
                    d[(r, q)] = t1

                if (p, t1) in d:
                    t2 = d[(p, t1)]
                elif (t1, p) in d:
                    t2 = d[(t1, p)]
                else:
                    t2 = gcd(p, t1)
                    d[(p, t1)] = t2
                    d[(t1, p)] = t2
                ans += t2
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
def gcd(m,n):
    if n==0:
        return m
    return gcd(n,m%n)
##print(gcd(5,3))
##print(gcd(2,4))
k=int(input())
d=defaultdict(int)
t=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            if list((i,j,k)) in [list(x) for x in d.keys()]:
                t+=d[(i,j,k)]
            else:
                d[tuple(sorted((i,j,k)))]=gcd(i,gcd(j,k))
                t+=d[tuple(sorted((i,j,k)))]
print(t)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
import itertools
import numpy as np

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

K=int(input())
 
l = [i for i in range(1,K+1)]
 
temp_sum=[]
for j in itertools.product(l, repeat=3):
    temp_sum.append(gcd_list(list(j)))

print(np.sum(temp_sum))

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

k = int(input())
tmp = 0
for a in range(1, k+1):
  for b in range(1, k+1):
    for c in range(1, k+1):
      tmp += gcd_list([a, b, c])
print(tmp)

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:
k = int(input())
ans = 0
import math
from functools import reduce

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

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 collections import deque
ans = deque()
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            ans.append(math.gcd(math.gcd(i, j), l))
print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
import math

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import functools

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

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
k =int(input())
ans = 0
for a in range(k):
  for b in range(k):
    for c in range(k):
      abc = [a+1,b+1,c+1]
      ans += gcd(abc)
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

K = int(input())
total = 0

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

Submission status: Time Limit Exceeded

Solution code:
import math
b=int(input())+1
sum=0
for x in range(1,b):
    for y in range(1,b):
        for z in range(1,b):
            if x==y and x==z:
                sum+=x
            elif x==y or z==y:
                sum+=math.gcd(x, z)
            elif x==z:
                sum+=math.gcd(y, z)
            else:
                sum+=math.gcd(x, math.gcd(y, z))
print(sum)

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
n = int(input())

lst = [_ for _ in range(1, n+1)]
lst = list(itertools.product(lst, repeat=3))

ans = sum([math.gcd(math.gcd(_[0],_[1]),_[2]) for _ in lst])

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import fractions
import math
k=int(input())
m=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for p in range(1,k+1):
            l=[i,j,p]
            m+=reduce(fractions.gcd,l)
print(m)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b):
  ret = d[a][b]
  if ret != 0:
    return ret
  while b:
    a,b = b,a%b
  d[a][b] = a
  d[b][a] = a
  
  return a

def gcd2(A):    
  ret = gcd(gcd(A[0],A[1]),A[2])    
  return ret

n = int(input())

d = [[0]*(n+1) for _ in range(n+1)]

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)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
from functools import reduce


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


K = int(input())
GCD = 0
range_list = list(range(1, K+1))
iterator = itertools.product(range_list, range_list, range_list)
for (a, b, c) in iterator:
    GCD += gcd(a, b, c)

print(GCD)

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

N=int(input())


ans=0

i=1
ans=0
while i<=N:
    j=1
    while j<=N:
        k=1
        while k<=N:
            ans+=math.gcd(math.gcd(i,j),k)
            k+=1
        j+=1
    i+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

K = int(input())

sum = 0

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

print(sum)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

N = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
n = int(input())
memo = {}
ans = 0
for a in range(1, n+1):
  for b in range(1, n+1):
    for c in range(1, n+1):
      elem = [a, b, c]
      elem.sort()
      if (a, b, c) not in memo:
        gcd_ans = gcd(gcd(a,b),c)
        memo[(a, b, c)] = gcd_ans
      else:
        gcd_ans = memo[(a, b, c)]
      ans += gcd_ans
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
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+=np.gcd(a,np.gcd(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)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
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'

# リストを改行区切りで出力する
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 = []
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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    ans=0
    K=int(input())
    KK=[i for i in range(1,K+1)]
    from functools import reduce
    from math import gcd

    I=list(product(KK,repeat=3))
    for i in I:
        ans+=reduce(gcd,i)
    print(ans)


resolve()

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

n = int(input()) 
sum1 = 0
for a in range(1,n+1):
    for b in range(1,n+1):
        for c in range(1,n+1):
            sum1= sum1 + gcd(a,b,c)
            
print(sum1)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

K = int(input().rstrip())
ret = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ret += gcd_3num(a, b, c)
print(ret)

Submission status: Time Limit Exceeded

Solution code:
import math

import math
from functools import reduce

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

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

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

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,c)
            s = s + d

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

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

k=int(input())
ans=0

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
goal = 0
n = int(input())
n+=1
for i in range(1,n):
    for j in range(1,n):
        for k in range(1,n):
            list1 = [i,j,k]
            ans = list1[0]
            for m in range(1, 3):
                ans = math.gcd(ans, list1[m])
            goal +=ans

print(goal)

Submission status: Time Limit Exceeded

Solution code:
import math

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

print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
K = 200
ans = 0
def gcd(*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):
      ans += gcd(i,j,k)
print(ans)

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce
k = int(input())
def GCD(*numbers):
    return reduce(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 math
from functools import reduce
K = int(input())
ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            num = [i,j,k]
            ans += reduce(math.gcd, num)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

if __name__ == '__main__':
    N = int(input())
    total = 0
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            for k in range(1, N + 1):
                total += math.gcd(k, math.gcd(j, i))
    print(total)

Submission status: Time Limit Exceeded

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

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())
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
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:
K = int(input())

import math
from functools import reduce

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

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

print(sum(dammy))

Submission status: Time Limit Exceeded

Solution code:
import math
K=int(input())
S=K
T=K
Q=0
for i in range(1,K+1):
    for i1 in range(1,S+1):
        for i2 in range(1,T+1):
            Q=Q+math.gcd(i2,math.gcd(i,i1))

print(Q)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

k = int(input())

# # nは組み合わせの数
# n = k**3

L = []
for i in range(1, k+1):
    for j in range(1, k+1):
        for p in range(1, k+1):
            L.append(gcd(i, j, p))

print(sum(L))

Submission status: Time Limit Exceeded

Solution code:
import math

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
gcd_memo = {}


def gcd(a, b):
    if b == 0:
        return a
    else:
        r = a % b
        gcd_memo[(a, b)] = gcd(b, r)
        return gcd_memo[(a, b)]


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

Submission status: Time Limit Exceeded

Solution code:
import fractions
k = int(input())
cnt = 0
lists = []
for i in range(1,k+1):
    for j in range(1,k+1):
        lists.append(fractions.gcd(i,j))

for i in lists:
    for j in range(1,k+1):
        cnt += fractions.gcd(i,j)
print(cnt)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for q in range(1, K+1):
            count += math.gcd(math.gcd(i,j),q)
print(count)