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

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

ans = 0
if n == 1:
    ans = 1
else:
    for i in range(n):
        i = i + 1
        #ans = ans + i #(i,i,i)
        for j in range(n):
            j = j + 1
            for k in range(n):
                k = k + 1
                ij = gcd(i,j)
                ans = ans + gcd(ij,k)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
import itertools

limit_num = int(input())

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

result = 0

for num in list(itertools.product(range(1, limit_num + 1), repeat=3)):
	result += gcd(num)

print(str(result))

Submission status: Time Limit Exceeded

Solution code:
import math 
from itertools import product
from functools import reduce
def gcd(*numbers):
  return reduce(math.gcd,numbers)
K=int(input())
A=[]
a_s=range(1,K+1)
b_s=range(1,K+1)
c_s=range(1,K+1)
for a,b,c in product(a_s,b_s,c_s):
  s=gcd(a,b,c)
  A.append(s)
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding=utf_8 -*-
import math
from functools import reduce

K = int(input())
def gcd(*numbers):
    return reduce(math.gcd, numbers)
result = []
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            result.append(gcd(a,b,c))
print(sum(result))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
l=[1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199]
a=0
b=0
#for i in range(K):
#    b+=
K=int(input())
for i in range(1,K+1):
    if i in l:
        a+=K**2 +(i-1)*(K//i)**2
    else:
        for j in range(1,K+1):
            for r in range(1,K+1):
                a+=gcd(i,j,r)
print(a)

Submission status: Time Limit Exceeded

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

result = 0

# 3つとも等しい数字
for i in range(1, k+1):
    result += i

# 2つが等しくて、1つが異なる数字
for i in range(1, k+1):
    liste = list(range(1, k+1))
    liste.pop(i-1)
    for j in liste:
        result += (gcd(i, j))*3

# 3つとも異なる
for set in list(itertools.combinations(range(1, k+1), 3)):
    result += (gcd(gcd(set[0], set[1]), set[2]))*6

print(result)

Submission status: Time Limit Exceeded

Solution code:
import fractions
import sys
readline = sys.stdin.buffer.readline
s =int(readline().rstrip().decode())
def gcdsp(x,y,z):
    t =fractions.gcd(x,y)
    return fractions.gcd(t,z)
res = 0
for i in range(s):
    for j  in range(s):
        for k  in range(s):
            if i < j and j <= k:
                res += gcdsp(i+1, j+1, k+1)
res1 =0
for l in range(s):
    res1 += gcdsp(l+1,l+1,l+1)
print(6*res+res1)

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
sum=0
for i in range(1,a+1):
  for j in range(1,a+1):
    for k in range(1,a+1):
      div=1
      for m in range(1,min(i,j,k)+1):
        if i%m==0 and j%m==0 and k%m==0:
          div=m
      sum+=div
print(sum,end="")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
#import math
from fractions import gcd

def main():

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

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

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

    K = first_input[0]

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

    print(gcd_sum)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

lst = [_ for _ in range(1, n+1)]
lst2 = list(itertools.permutations(lst, 3))
lst3 = list(itertools.permutations(lst, 2))
l2 = sum([math.gcd(math.gcd(_[0],_[1]),_[2]) for _ in lst2])
l3 = sum([math.gcd(_[0], _[1]) for _ in lst3]) 
l4 = sum(lst)

ans = l2 + l3 * 3 + l4

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

import math
from functools import reduce
import itertools


K = intinp()

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

K= int(input())
sum = 0

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


print(sum)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

import math
from functools import reduce

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

from itertools import product
from functools import reduce

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


a = input()
a = int(a)
count = 0
l = range(1, a + 1)
m = range(1, a + 1)
n = range(1, a + 1)

for x, y, z in product(l, m, n):
            count +=  gcd(x, y, z)

print(count)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

result_dict = {}
def gcd(x, y):
    if x > y:
        x, y = y, x
    if x == 0:
        return y
        
    global result_dict
    if x not in result_dict:
        result_dict[x] = {}
    if y in result_dict[x]:
        return result_dict[x][y]

    temp = gcd(y % x, x)
    result_dict[x][y] = temp
    return temp

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
memo = {}
def gcd(x,y):
    if x < y:
        x,y = y,x
    if (x,y) in memo:return memo[(x,y)]
    if y == 0:return x
    memo[(x,y)] = gcd(y,x%y)
    return memo[(x,y)]
ans = 0
temp = []
for i in range(1,K+1):
    for j in range(1,K+1):
        temp.append(gcd(i,j))
for i in range(1,K+1):
    for num in temp:
        ans += gcd(i,num)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
ans = 0
import math
from functools import reduce
import itertools

def gcd(num):
    return reduce(math.gcd, num)
numlist = list(range(1, k+1))
l = list(itertools.product(numlist, repeat=3))

for v in l:
    ans += gcd(v)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np

a = int(input())
result = 0
mat = np.array(list(itertools.product(range(1, a+1), repeat=3)))
result = np.sum(np.gcd(np.gcd(mat[:, 0], mat[:, 1]),mat[:, 2]))

print(result)

Submission status: Time Limit Exceeded

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

for l in range(N):
    for m in range(N):
        for n in range(N):
            C+=math.gcd(math.gcd(l+1,m+1),n+1)

print(C)

Submission status: Time Limit Exceeded

Solution code:
import math
K = int(input())
ans =0
def koyakusu(A,B,C):
  kotae = math.gcd(A,B)
  kotae = math.gcd(kotae,C)
  return kotae
  
  
for a in range(1,K+1):
  for b in range(1,K+1):
    for c in range(1,K+1):
      ans +=koyakusu(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())

ans = 0
for i in range(K):
    for j in range(K):
        for k in range(K):
            if i+1 == j+1 and j+1==k+1 and i+1 == k+1:
                ans += i+1
             
            elif i+1 == j +1:
                ans += gcd(i+1,k+1)
            elif j+1 == k+1:
                ans += gcd(i+1,k+1)
            elif i+1 == k+1:
                ans += gcd(i+1,j+1)
            elif i+1 == 1 or j+1 == 1 or k+1 == 1:
             

                ans +=1
            
            else:
             

                ans += gcd(i+1,j+1,k+1)
            #1-Kまで
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):
            mid = math.gcd(a, b)
            gcd = math.gcd(mid, c)
            ans = ans + gcd
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def find_gcd(x, y, gcd_dict):
    if (x, y) in gcd_dict.keys():
        return gcd_dict[x, y]
    elif (y, x) in gcd_dict.keys():
        return gcd_dict[y, x]
    else:
        x_first = x
        y_first = y
        gcd_dict[x, y] = x
        while(y): 
            x, y = y, x % y 

        #print(x_first, y_first)
        gcd_dict[x_first, y_first] = x

    return x

nums = int(input())
result = 0

gcd_dict = {}

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, gcd_dict)
            result += find_gcd(gcd, l, gcd_dict)

print(result)

Submission status: Time Limit Exceeded

Solution code:
def gcd(x, y):
    if x < y: x, y = y, x
    while y != 0:
        x, y = y, x % y
    return x

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):
            if i == j == k:
                ans += i
            elif i == k or j == k:
                continue
            elif i == j and j != k:
                ans += gcd(k, gcd(i, j)) * 3
            elif i < j < k:
                ans += gcd(k, gcd(i, j)) * 6

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
K=int(input())
s=0
d=0
for a in range(1,K+1):
    for b in range(1,K+1):
        if a>b:
            if a%b==0:
                d=b
            else:
                d=np.gcd(a%b,b)
        if a<b:
            if b%a==0:
                d=a
            else:
                d=np.gcd(b%a,a)
        if a==b:
            d=a
        for c in range(1,K+1):
            if c>d:
                if c%d==0:
                    s+=d
                else:
                    s+=np.gcd(c%d,d)
            if c<d:
                if d%c==0:
                    s+=c
                else:
                    s+=np.gcd(d%c,c)
            if c==d:
                s+=c
print(s)

Submission status: Time Limit Exceeded

Solution code:
import math

def gcd(a,b,c):
    if a == b==c:
        return a
    elif a ==b and b!=c :
        return math.gcd(a,c)
    elif a ==c and b!=c:
        return math.gcd(a,b)
    elif b ==c and a!=c:
        return math.gcd(a,b)
    else:
        d = math.gcd(a,b)
        return math.gcd(d,c)
        
cnt=0
K = int(input())
for i in range(1,K+1):
    for m in range(1,K+1):
        for u in range(1,K+1):
            cnt +=gcd(i,m,u)
print(cnt)

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())
Kr = [range(1, K+1) for i in range(3)]

items = itertools.product(*Kr)

sum_ = 0
for p in items:
    p = sorted(p)
    sum_ += gcd(gcd(p[0], p[1]), p[2])
print(sum_)

Submission status: Time Limit Exceeded

Solution code:
import itertools


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

K = int(input())

a = [i for i in range(1, K + 1)]
b = [i for i in range(1, K + 1)]
c = [i for i in range(1, K + 1)]

# L = list(itertools.product(a,b,c))
ans = 0

for x in a:
    for y in b:
        for z in c:
            if x == 1 or y == 1 or z == 1:
                ans += 1
            else:
                n = gcd(x,y)
                ans += gcd(z,n)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
def gcd(a,b,c):
    if a <b:
        a,b=b,a
    while a%b != 0:
        a,b= b,a%b
    if b < c:
        b,c=c,b
    while b % c != 0:
        b,c = c,b%c
    return c
x=0
for i in range(1,K+1):
    for j in range(1,K+1):
        for l in range(1,K+1):
            if (i==1) or (j==1) or (l==1):
                x+=1
            elif (j%i==i) or (l%j==j) or(l%i==i):
                x+=1
            else:
                x += gcd(i,j,l)
print(x)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K = int(input())

res = 0

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools

def culc_gcd_of_3(l_p):
    answer = 0
    for x in l_p:
        temp = math.gcd(x[0], x[1])
        
        if temp == 1:
            answer += 1
        else:
            answer += math.gcd(x[2], temp)
    
    return answer
 
 
K = int(input())
l_p = list(itertools.product(range(1, K+1), range(1, K+1), range(1, K+1)))
 
print(culc_gcd_of_3(l_p))

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
x = range(1,n+1)
gcd = 0
for a in x:
    for b in x:
        for c in x:
                if a == b and b == c and c== a:
                    gcd += a
                elif a == b:
                    gcd += math.gcd(a, c)
                else:
                    gcd += math.gcd(math.gcd(a,b), c)
print(gcd)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
from functools import reduce


a = int(input())
b = list(itertools.product(range(1,a+1),repeat=3))
c = 0

for i in b:
    m = [i[0],i[1],i[2]]
    n = reduce(math.gcd,m)
    c += n

print(c)

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

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



def sigma2(frm, to):
    r = 0;
    for i in range(frm, to+1):
        for j in range(frm, to+1):
            for k in range(frm, to+1):
                r+=f(i,j,k)
    return r

print(sigma2(1,n))
# print(sum(sigma2(1,n)+sigma2(1,n)+sigma2(1,n)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())

lis = tuple([i for i in range(1,K+1)])
a = 0

for i in lis:
    for j in lis:
        i_j= math.gcd(i,j)
        for k in lis:
            i_k = math.gcd(i,k)
            i_j_k = math.gcd(i_j,i_k)
            a += i_j_k

print(a)

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())
cnt = 0

for l in range(1,k+1):
    for m in range(1,k+1):
        for n in range(1,k+1):
            tmp = math.gcd(l,m)
            if tmp == 1:
                cnt += 1
            else:
                cnt += math.gcd(tmp,n)
            
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

n = int(input())

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

num = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            num += int(gcd_list([i, j, k]))

print(num)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

def get_gcd(a, b, c):
    min_ab = min(a, b)
    max_ab = max(a, b)
    amari = max_ab % min_ab
    if amari == 0:
        gcd1 = min_ab
    else:
        x = min_ab
        y = amari
        while y != 0:
            amari = x % y
            if amari == 0:
                gcd1 = y
                break
            x = y
            y = amari
    min_2 = min(c, gcd1)
    max_2 = max(c, gcd1)
    amari = max_2 % min_2
    if amari == 0:
        gcd2 = min_2
    else:
        x = min_2
        y = amari
        while y != 0:
            amari = x % y
            if amari == 0:
                gcd2 = y
                break
            x = y
            y = amari

    return gcd2


k = int(input())
ans = 0

for a in range(1, k+1):
    for b in range(1, k+1):
        if b == a:
            continue
        for c in range(1, k+1):
            if c == a or c == b:
                continue
            ans += get_gcd(a, b, c)

for a in range(1, k+1):
    b = a
    for c in range(1, k+1):
        if c == a:
            continue
        ans += get_gcd(a, b, c) * 3

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from math import gcd


k = int(input())
B=list()

for i in range(1,k+1):
  for j in range(1,k+1):
    for k in range(1,k+1):
        a=[i,j,k]
        b = reduce(gcd,a)
        B.append(b)
print(sum(B))

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
total = 0

def gdc(x,y):
  if x%y==0:
    return y
  return gdc(y, x%y)

for a in range(K):
  for b in range(K):
    for c in range(K):
      tmp = [a+1,b+1,c+1]
      tmp.sort()
      total += gdc(c+1, gdc(b+1, a+1))
print(total)

Submission status: Time Limit Exceeded

Solution code:
import math
k = int(input())
box = []
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1,k+1):
      gap = math.gcd(i,j)
      gap2 = math.gcd(gap,l)
      box.append(gap2)
print(sum(box))

Submission status: Time Limit Exceeded

Solution code:
def gcd(i, j):
  if i % j != 0:
    return gcd(j, i % j)
  else:
    return j  

def gcd3(a, b, c):
  a = gcd(a, b)
  a = gcd(a, c)
  return a

k = int(input())
total = 0

for i in range(1, k+1):
  for j in range(1, k+1):
    for t in range(1, k+1):
      if i == 1 or j == 1 or t == 1:
        g = 1
      elif i == 2 or j == 2 or t == 2:
        if i % 2 == 0 and j % 2 == 0 and t % 2 == 0:
          g = 2
        else:
          g = 1
      else:
      	g = gcd3(i, j, t)

      total += g

print(total)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

s=int(input())
f = 0
for a in range(1,s+1):
  for b in range(1,s+1):
    for c in range(1,s+1):
      f += gcd(a,b,c)

print(f)

Submission status: Time Limit Exceeded

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
c = 0
  
for i, j, k in itertools.product(range(1,n+1), range(1,n+1), range(1,n+1)):
      c += gcd(i,j,k)
      
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())

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
import itertools
import collections
n = int(input())
ree = list(itertools.combinations_with_replacement(range(1, n+1), 3))
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

re = []
for i in range(len(ree)):
  k = len(collections.Counter(ree[i]))
  if k == 3:
    re.append(gcd_list(list(ree[i])) * 6)
  elif k == 2:
    re.append(gcd_list(list(ree[i])) * 3)
  else:
    re.append(gcd_list(list(ree[i])))
print(sum(re))

Submission status: Time Limit Exceeded

Solution code:
import math
n=int(input())
ans=(1+n)*n//2

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


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:
                ans+=0
            elif i==j or j==k:
                ans+=math.gcd(i,k)
            elif i==k:
                ans+=math.gcd(i,j)
            else:
                ans+=gcd3(i,j,k)
            
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)
 
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
 
lst = []
for i in range(k):
    a = i + 1
    for j in range(k):
        b = j + 1
        for l in range(k):
            c = l + 1
            koyakusu = gcd(a, b, c)
            lst.append(koyakusu)
kotae = sum(lst)
print(kotae)

Submission status: Time Limit Exceeded

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

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

N = int(input())
result = 0

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
k = int(input())
li = []
cnt = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            li.append(gcd(gcd(i, j), gcd(j, l)))
print(sum(li))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce

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

k = int(input())
ans = 0
g = []
for a in range(1,k+1):

  for b in range(1,k+1):
    
    g.append(gcd(a,b))


for c in range(1, k+1):
  for i in g:
    ans += gcd(c,i)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce


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

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

items = itertools.product(range(1, K+1), range(1, K+1), range(1, K+1))

sum_ = 0
for p in items:
    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
def koyakusu(A,B,C):
  kotae = A
  kotae = math.gcd(kotae,B)
  kotae = math.gcd(kotae,C)
  return kotae
  
  
for a in range(1,K+1):
  for b in range(1,K+1):
    for c in range(1,K+1):
      ans +=koyakusu(a,b,c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
import itertools

limit_num = int(input())

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

result = 0

for num in list(itertools.product(range(1, limit_num + 1), repeat=3)):
	result += gcd(num)

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

n = int(input())

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

result = []
for i in range(1, n+1):
  for j in range(1, n+1):
    for k in range(1, n+1):
      result.append([i, j, k])

num = 0
for l in range(0, len(result)):
    num += int(gcd_list(result[l]))

print(num)

Submission status: Time Limit Exceeded

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""
 
"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""
 
"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""
 
# 最大公約数 と 最小公倍数
"""def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def lcm(a,b):
  g = gcd(a,b)
  return (a * b) // g"""
 
# 二分探索
"""import bisect # 二分探索
print(A,bisect.bisect_left(A,4))
print(C,n - bisect.bisect_right(C,4))
print(sum(bisect.bisect_left(A,b) * (n-bisect.bisect_right(C,b)) for b in B))"""
 
# 円周率 pi
"""import math
pi_ = math.pi"""
 
# エラトステネスの篩
"""def Erato(n):
    prime = []
    is_prime = [True] * (n+1)
    p = 0
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2,n+1):
      if is_prime[i] == True:
        prime.append(i)
        p += 1
        for j in range(2 * i,n+1,i):
          is_prime[j] = False
    return p"""
 
def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def main():
  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(a,fractions.gcd(b,c))
  print(ans)
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

data=int(input())
result = [[i+1, j+1, k+1] for i in range(data) for j in range(data) for k in range(data)]

ans=[]

for n in result:
  ans.append(gcd(n[0],n[1],n[2]))
  
print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
y=int(input())
b=[[i,j,k]  for i in range(1,y+1) for j in range(1,y+1) for k in range(1,y+1) ]
c=[]
for l in range(y**3):
    import math
    a = b[l]
    ans1 = math.gcd(a[0], a[1])
    ans2 =math.gcd(ans1,a[2])
    c.append(ans2)
print(sum(c))

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
from numba import njit
 
@njit
def culc_gcd_of_3(l_p):
    answer = 0
    for x in l_p:
        temp = math.gcd(x[0], x[1])
        
        if temp == 1:
            answer += 1
        else:
            answer += math.gcd(x[2], temp)
    
    return answer
 
 
K = int(input())
l_p = list(itertools.product(range(1, K+1), range(1, K+1), range(1, K+1)))
 
print(culc_gcd_of_3(l_p))

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())

res = 0

dict = [[0 for i in range(201)] for j in range(201)]
tdict = [[[0 for i in range(201)] for j in range(201)] for k in range(201)]
# for d in dict:
#     print(d)

def fun(a, b):
    if dict[a][b] != 0:
        # 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 tdict[a][b][c] != 0:
        return tdict[a][b][c]
    if dict[a][b] != 0:
        res = fun(dict[a][b], c)
        tdict[a][b][c] = res
        tdict[a][c][b] = res
        tdict[b][a][c] = res
        tdict[b][c][a] = res
        tdict[c][a][b] = res
        tdict[c][b][a] = res
        return res
    elif dict[b][c] != 0:
        res = fun(a, dict[b][c])
        tdict[a][b][c] = res
        tdict[a][c][b] = res
        tdict[b][a][c] = res
        tdict[b][c][a] = res
        tdict[c][a][b] = res
        tdict[c][b][a] = res
        return res
    else:
        res = fun(a, fun(b, c))
        tdict[a][b][c] = res
        tdict[a][c][b] = res
        tdict[b][a][c] = res
        tdict[b][c][a] = res
        tdict[c][a][b] = res
        tdict[c][b][a] = res
        return res

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)

# from itertools import combinations
# L = [i for i in range(1,k+1)]
# comblist = [comb for comb in combinations(L, 3)]
#
# print(comblist)
#
# for comb in comblist:
#     res += find_gcd(comb[0], comb[1], comb[2])*6


print(res)

Submission status: Time Limit Exceeded

Solution code:
k = int(input()) + 1
ans = 0
 
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
 
for i in range(1,k):
  for j in range(1,k):
    for l in range(1,k):
      ans += gcd(gcd(i, j),l)
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
import itertools

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

N = int(input())

i = 0
for a, b, c in itertools.product(range(1,N+1), range(1,N+1),range(1,N+1)):
    i += gcd(a, b, c)

print(i)