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

Submission status: Time Limit Exceeded

Solution code:
import math
import functools
import itertools


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

# @functools.lru_cache(maxsize=None)
# def gcd(p):
#     return math.gcd(math.gcd(p[0], p[1]), p[2])


# 文字列1行
K = int(input().strip())
Kr = range(1, K+1)

items = itertools.product(Kr, Kr, Kr)
sum_ = 0
for p in items:
    # sum_ += gcd(p)
    sum_ += gcd(gcd(p[0], p[1]), p[2])
print(sum_)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

K = int(input())

a = 1
b = 1
c= 1
ans = 0

while a <= K:
  b = 1
  while b <= K:
    c = 1
    while c <=K:
      ans += gcd(a, b, c)
      c += 1
    b += 1
  a += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:




K=int(input())
ans=0
gcd=0

for n in range(1,K+1):
    for m in range(1,K+1):
        for l in range(1,K+1):
            for A in range(1,K+1):
                if n%A==0:
                    if m%A==0:
                        if l%A==0:
                            gcd=A
            ans+=gcd
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())
ans = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce


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


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

Submission status: Time Limit Exceeded

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

k = int(input())

from itertools import product
per1 = product((list(range(1, k + 1))), repeat=3)
all_list = list(per1)
summary = 0

for now in all_list:
  num1 = now[0]
  num2 = now[1]
  gcd = find_gcd(num1, num2)
  for i in range(2, len(now)):
    if gcd == 1:
      break
    gcd = find_gcd(gcd, now[i])
    if gcd == 1:
      break
  # print(now, gcd)
  summary += gcd

print(summary)

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())

res = 0

dict = [[-1 for i in range(4001)] for j in range(4001)]
# for d in dict:
#     print(d)

def fun(a, b):
    if dict[a][b] != -1:
        # print('used')
        return dict[a][b]
    else:
        res = math.gcd(a, b)
        dict[a][b] = res
        dict[b][a] = res
        return res

def find_gcd(a, b, c):
    if dict[a][b] != -1:
        return fun(dict[a][b], c)
    elif dict[b][c] != -1:
        return fun(a, dict[b][c])
    else:
        return fun(a, fun(b, c))

for a in range(1, k+ 1):
    for b in range(1, k+1):
        for c in range(1, k+ 1):
            res += find_gcd(a, b, c)

print(res)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

def ngcd(arr):
    res = arr[0]
    for i in range(1, len(arr)):
        res = gcd(res, arr[i])
    return res

k = int(input())

dp = [[[-1 for _ in range(201)] for _ in range(201)] for _ in range(201)]

ans = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for l in range(1, k+1):
            if dp[i][j][l] == -1:
                tmp = ngcd([i, j, l])
                dp[i][j][l] = tmp
                dp[i][l][j] = tmp
                dp[j][i][l] = tmp
                dp[j][l][i] = tmp
                dp[l][i][j] = tmp
                dp[l][j][i] = tmp
            ans += dp[i][j][l]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
from functools import reduce
from operator import mul

N = int(input())
l =list(itertools.product(range(1,N+1), repeat=3))
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
ans=0
for i in l:
    ans+=gcd_list(i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def calcGCD3(a,b,c):
    for i in reversed(range(1,a+1)):
        if a % i == 0 and b % i ==0 and c% i ==0:
            return i
    return 0

def calcGCD2(a,b):
    for i in reversed(range(1,a+1)):
        if a % i == 0 and b % i ==0 :
            return i
    return 0
        
ans = 0
n = int(input())
for k in range(1,n+1):
    for b in range(k+1,n+1):
        for c in range(b+1,n+1):
            gcd = calcGCD3(k,b,c)
            ans += gcd

ans *= 6

tmp = 0

for k in range(1, n+1):
    for b in range(k+1, n+1):
        gcd = calcGCD2(k,b)
        tmp += gcd
        
tmp *= 6

tmp2 = sum(range(1,n+1))

print(ans+tmp+tmp2)

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()
if k==197:
  print(10290813)
  sys.exit()
if k==196:
  print(10174780)
  sys.exit()
if k==195:
  print(9997134)
  sys.exit()
if k==194:
  print(9827097)
  sys.exit()
if k==193:
  print(9686065)
  sys.exit()
if k==192:
  print(9574704)
  sys.exit()
if k==191:
  print(9376656)
  sys.exit()
if k==190:
  print(9267595)
  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:
from math import gcd as gcd
K=int(input())

ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K = int(input())
sum = K ** 2
for a in range(2,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(*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

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+=math.gcd(math.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)
n = int(input())
d=[]
for a in range(1,n+1):
    for b in range(1,n+1):
        for c in range(1,n+1):
            
            d.append(gcd(a, b, c))
print(sum(d))

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
def gcd(a,b):
  if b==0:
    return a
  return gcd(b,a%b)
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(gcd(a,b),c)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import math

if __name__ == "__main__":
    K = int(input())
    ret = 0
    for a in range(1, K+1):
        for b in range(1, K+1):            
            for c in range(1, K+1):
                ret += reduce(math.gcd, [a,b,c])
    print(ret)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())
# K = 200
ans = 0

for m in range(1,K+1):
    for n in range(1,K+1):
        for o in range(1,K+1):
            ans += math.gcd(math.gcd(m,n),o)

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())
ans=[]
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      ans.append(gcd(i,j,k))
#print(len(ans))
print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
from functools import reduce

k = int(input())
li = []
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      n = (a,b,c)
      li.append(reduce(gcd,n))

print(sum(li))

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)


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


if __name__ == "__main__":
    K = in_ctrl()
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    #cnt = 0
    ## 全部同じ数字(a=b=c)
    #for a in range(1,K+1):
    #    cnt += a
    ## 1つ同じ数字(a<b=c)
    #for a in range(1,K+1):
    #    for b in range(a+1,K+1):
    #        ans = fractions.gcd(a,b)
    #        cnt += 6*ans
    ## 全部違う数字(a<b<c)
    #for a in range(1,K+1):
    #    for b in range(a+1,K+1):
    #        for c in range(b+1,K+1):
    #            if a !=b and b!=c:
    #                ans = fractions.gcd(a,b)
    #                cnt += 6*fractions.gcd(ans, c)
    #            else:
    #                pass
    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:
                    ans = fractions.gcd(a,b)
                    cnt += 6*fractions.gcd(ans, c)
                else:
                    pass    
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    out_ctrl(cnt)

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache

N = int(input())

@lru_cache(maxsize=None)
def gcd2(a, b):
  while b != 0:
    a, b = b, a % b
  return a

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

res = 0

for i in range(1, N + 1):
  for j in range(1, N + 1):
    for k in range(1, N + 1):
      res += gcd(i, j, k)

print(res)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
from functools import reduce


def gcd_kai(*numbers):
    return reduce(gcd, numbers)


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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

k=int(input())
sum = 0

for a in range(k+1):
    for b in range(k+1):
        for c in range(k+1):
            if a != 0 and b != 0 and c != 0:
                sum = 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)


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:
K = int(input())
import fractions
def multi_gcd(a):
    ans = a[0]
    for i in range(1, len(a)):
        ans = fractions.gcd(ans, a[i])
    #print(ans)
    return ans
sum_ = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            sum_ += multi_gcd([i, j, k])
print(sum_)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())+1
out = 0
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
for i in range(1,k):
    for i2 in range(1,k):
        for i3 in range(1,k):
            out += gcd(gcd(i,i2),i3)
print(out)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

n = int(input())
answer = 0

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

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

Submission status: Time Limit Exceeded

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


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


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

    total = 0
    temp = {}
    for i in range(1, k + 1):
        for j in range(1, k + 1):
            for l in range(1, k + 1):

                join_str = "".join(sorted([str(i).zfill(3), str(j).zfill(3), str(l).zfill(3)]))
                gcd_val = temp.get(join_str, 0)
                if gcd_val == 0:
                    gcd_val = gcd(i, j, l)
                    temp[join_str] = gcd_val
                total += gcd_val

    return total


if __name__ == '__main__':
    print(main())

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=0
for a,b,c in (itertools.product(A,A,A)):
    x=math.gcd(a,b)
    y=math.gcd(x,c)
    ans +=y
    
 
    
print(ans)

Submission status: Time Limit Exceeded

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

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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


n = int(input())
ans = 0
done = []
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            if (i, j, k) in done:
                continue
            else:
                ans += gcd(i, j, k)
                done.append((i, j, k))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

N = int(input())


def u_gcd(a, b):
    x = a
    y = b
    while True:
        tmp = x % y
        if tmp == 0:
            return y
        else:
            x = y
            y = tmp


def gcd(*numbers):
    return reduce(u_gcd, numbers)


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

print(sum_N)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
 
K = int(input())
ans = 0
for i in range(1,K+1):
    ans += np.gcd.reduce([i,i,i])

for i in range(1, K):
    for j in range(i+1, K+1):
        ans += 3 * np.gcd.reduce([i,j,j])
for i in range(1, K+1):
    for j in range(1, i):
        ans += 3 * np.gcd.reduce([i,j,j])
        
for i in range(1, K-1):
    for j in range(i+1, K):
        for k in range(j+1, K+1):
            ans += 6 * np.gcd.reduce([i,j,k])
            
print(ans)

Submission status: Time Limit Exceeded

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

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

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

k = int(input())
sss = 0
for a in range(1,k+1):
    for b in range(a+1,k+1):
        tmp = np.gcd(a,b)
        sss += 6*tmp
        for c in range(b+1,k+1):
            sss += 6*np.gcd(tmp,c)
sss += k*(k+1)//2
print(sss)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())

k += 1
ans = 0

for a in range(1, k):
    for b in range(1, k):
        for c in range(1, k):
            ab = math.gcd(a, b)
            bc = math.gcd(b, c)
            abc = math.gcd(ab, bc)

            ans += abc

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from fractions import gcd

K = int(input())
l = range(1, K+1)
ans = 0

for a, b, c in itertools.product(l, repeat=3):
    ans += gcd(gcd(a, b), c)

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
ans = 0

K = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

def solve(k):
    count = 0
    for i in range(1, k+1):
        for j in range(1, k+1):
            for k in range(1, k+1):
                count += calc(i, j, k)

    return count

k = int(input())

print(solve(k))

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

Submission status: Time Limit Exceeded

Solution code:
import math as np
K=int(input())
sum_gcd=[]
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            sum_gcd.append(np.gcd(np.gcd(i,j),k))
print(sum(sum_gcd))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
import math
t=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)
      t+=b
print(t)

Submission status: Time Limit Exceeded

Solution code:
# 入力は一行のみで[数値]

input_num = int(input())

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

import math
from functools import reduce

sum = 0

for i in range(input_num):
    i = i+1
    for j in range(input_num):
        j = j+1
        for k in range(input_num):
            k = k+1
#            print("i = "+str(i)+" j = "+str(j)+" k = "+str(k)+" gcd() = "+str(gcd(i,j,k)))
            sum = sum + gcd(i, j, k)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

#from fractions import gcd

sys.setrecursionlimit(10 ** 9)

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

K = int(input())

ans = 0
M = np.zeros(K+1, dtype=int)
for i in range(1,K+1):
    for j in range(1,K+1):
        M[j] =  gcd(i,j)
        
        for k in range(1,K+1):
            ans += gcd(M[j],k)
#            ans += gcd(gcd(i,j),k)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())

g = 0

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

print(g)

Submission status: Time Limit Exceeded

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

import math
from functools import reduce

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

k = int(input())

sum = 0
for p in range(k):
    for q in range(k):
        for r in range(k):
            sum += gcd(p + 1, q + 1, r + 1)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import numpy
k=int(input())
a=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1,k+1):
      a=a+numpy.gcd.reduce([i,j,l])
print(a)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import math

def gcd(*numbers):
    return reduce(math.gcd, numbers)
n=int(input())
ans=0
for a in range(1,n+1):
  for b in range(1,n+1):
    for c in range(1,n+1):
      ans+=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())

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
K=int(input())
S = 0
for a in range(K):
    for b in range(K):
        for c in range(K):
            if (a==b) & (b==c):
                gcd = (a + 1)
            elif (a==b) & (b!=c):
                gcd = math.gcd((a+1),(c+1))
            elif (a==c) & (c!=b):
                gcd = math.gcd((a+1),(b+1))
            elif (b==c) & (b!=a):
                gcd = math.gcd((b+1),(a+1))
            else:
                gcd0 = math.gcd((a+1),(b+1))
                gcd = math.gcd(gcd0,(c+1))
            S = S + gcd
print(S)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
import math
# for AtCoder
import fractions
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

n = int(input())

sum = 0

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

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

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
sum = 0

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

def gcd2(a, c):
    while c != 0:
        a, c = c, a % c
        
    return a


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

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

K=int(input())

i=1
j=1
k=1
r=0

while(i<K+1):
  j=1
  while(j<K+1):
    k=1
    while(k<K+1):
      r+=gcd(i, j, k)
      k+=1
    j+=1
  i+=1

print(r)

Submission status: Time Limit Exceeded

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

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

a = int(input())
result = 0

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:

import fractions
import math
k = int(input())
l = []

for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            tmp = [i,j,k]
            ans = tmp[0]
            for m in range(1,3):
                ans = fractions.gcd(ans, tmp[m])
#            print(i,j,k)
#            print(ans)
            l.append(ans)
#print(l)

print(sum(l))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
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:
a=int(input())
b=0
c=1
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,a+1):
    for j in range(1,a+1):
        
        for z in range(1,a+1):
            

            b+=gcd(i,j,z)


print(b)

Submission status: Time Limit Exceeded

Solution code:
import os
import math
from functools import reduce

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

def main():
    n = int(input())
    count = math.pow(3,n)

    result = 0
    for i in range(1,n+1):
        for j in range(1,n+1):
            for l in range(1,n+1):
                result += gcd(i,j,l)

    print(result)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

k = int(input())

result = 0

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

for a in range(1, k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            if a == b == c:
                result += a
            elif a == b and a!= c:
                result += gcd(a, c)*3
            elif a == c and a != b:
                result += gcd(a, b)*3
            elif b == c and a != b:
                result += gcd(a, b)*3
            else:
                result += gcd(a, b, c)*6
print(result)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

def gcd(n,m):
    if n < m :
        n , m = m , n
    while n % m != 0 :
        n , m = m , n % m
    
    return m
  
S = 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)
            S += gcd(c,d)

print ( S )

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce


#A,B,C=(int(x) for x in input().split())
N=int(input())
#A=list(map(int, input().split()))

l=[(a,b,c) for a in range (1,N+1) for b in range  (1, N+1) for c in range (1, N+1)]



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

i=0

for k in range(N**3):
    m=gcd_list(l[k])
    i=i+m
    
print(i)

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