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())
count = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            tmp = 0
            tmp = math.gcd(i, j)
            count += math.gcd(tmp, k)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np
import itertools

k = int(input())
tot = 0

g = np.array([[-1] * (k + 1)] * (k + 1), dtype=np.int64)

for l, m, n in itertools.product(range(1, k + 1), 
                                 range(1, k + 1), range(1, k + 1)):
    if g[l][m] == -1:
        g[l][m] = math.gcd(l, m)
    lm_gcd = g[l][m]

    if g[lm_gcd][n] == -1:
        g[lm_gcd][n] = math.gcd(lm_gcd, n)
    tot += g[lm_gcd][n]
    
print(tot)

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)


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


# 文字列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:
    if 1 in p:
        sum_ += 1
    else:
        p = sorted(p)
        sum_ += gcd3(*p)
print(sum_)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())


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


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

print(result)

Submission status: Time Limit Exceeded

Solution code:
import math
input=int(input())
a=[1,1,1]
out=0
for j in range(1,input+1):
    a[2]=j
    a[0]=1
    a[1]=1
    for s in range(1,input+1):
        a[1]=s
        a[0]=1
        for k in range(1,input+1):
            a[0]=k
            ans = a[0]
            for i in range(1, 3):
                ans = math.gcd(ans, a[i])
            out=out+ans
print(out)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import math 
  
w, h = 201, 201;
m = [[0 for x in range(w)] for y in range(h)] 
m3 = [[[0 for x in range(w)] for y in range(h)] for y in range(h)]

k = int(input())
s = 0

for a in range(1,k+1):
	for b in range(1,k+1):
		for c in range(1,k+1):
			x1, x2, x3 = sorted([a, b, c])
			if m3[x1][x2][x3] == 0:
				if m[x2][x3] == 0:
					m[x2][x3] = math.gcd(x2,x3)
				if m[x1][m[x2][x3]] == 0:
					m[x1][m[x2][x3]] = math.gcd(x1, m[x2][x3])
				m3[x1][x2][x3] = m[x1][m[x2][x3]]
			s += m3[x1][x2][x3]
print(s)

Submission status: Time Limit Exceeded

Solution code:
memo = [[[-1] * 201 for j in range(201)] for i in range(201)]

def gcd(numbers):
    numbers.sort()
    a = numbers[1]
    b = numbers[0]
    ans = b
    while True:
        q, mod = divmod(a, b)
        if mod == 0:
            break
        a = b
        b = mod
        ans = mod
    return ans

K = int(input())
numbers = []

for i in range(K, 0, -1):
    for j in range(i, 0, -1):
        for k in range(j, 0, -1):
            numbers.append([i, j, k])

gcd_sum = 0
for number in numbers:
    dup = len(set(number))
    a, b, c = number
    if memo[a][b][c] == -1:
        if dup == 1:
            ans = gcd([gcd([a, b]), c])
        elif dup == 2:
            ans = gcd([gcd([a, b]), c]) * 3
        else:
            ans = gcd([gcd([a, b]), c]) * 6
        memo[a][b][c] = ans
    gcd_sum += memo[a][b][c]

print(gcd_sum)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
import itertools
from scipy.special import comb

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

k = int(input())
cnt = 0
b = list(range(1, k+1))
b = list(map(str, b))

c = itertools.combinations_with_replacement(b, 3)

c = list(c)

f = []
for i in range(len(c)):
    d = list(map(int, c[i]))
    dd = list(set(d))
    if len(dd) == 1:
        e = dd[0]
        cnt += e
    elif len(dd) == 2:
        e = gcd(*dd)
        cnt += e*3
    else:
        e = gcd(*d)
        cnt += e*6

print(cnt)

Submission status: Time Limit Exceeded

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

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

numlist = list(range(1, k+1))
l = list(itertools.product(numlist, repeat=3))

ans = sum(map(gcd, l))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

k=int(input())
ans=[]
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:
#https://atcoder.jp/contests/abc162/tasks/abc162_c
# -*- coding: utf-8 -*-
import fractions
import itertools
N = int(input())
A = 0
M = []
T =0
for i in range(1,N+1):
  M.append(i)
for i in itertools.combinations_with_replacement(M, 3):
  tmp1 = list(i)
  tmp2 = fractions.gcd(tmp1[0],tmp1[1])
  tmp3 = fractions.gcd(tmp2,tmp1[2])
  if (tmp1[0]==tmp1[1] and tmp1[0]!=tmp1[2]) or (tmp1[1]==tmp1[2] and tmp1[1]!=tmp1[0]) or (tmp1[2]==tmp1[0] and tmp1[2]!=tmp1[1]):
    A += tmp3*3
  elif tmp1[0] != tmp1[1] and tmp1[0] != tmp1[2] and tmp1[1] != tmp1[2]:
    A += tmp3*6
  else:
    A += tmp3
  T +=1
print(A)

Submission status: Time Limit Exceeded

Solution code:

def q3():
    import math
    k = int(input())
    sum_n = 0
    gcd_2_dict = {}

    def gcd(n1, n2):
        if n1 == n2:
            return n2
        if n1 == 1:
            return 1
        if n2 % n1 == 0:
            return n1
        key = tuple([n1, n2])
        if key in gcd_2_dict:
            return gcd_2_dict[key]
        gcd_num = math.gcd(n1, n2)
        gcd_2_dict[key] = gcd_num
        return gcd_num

    import time
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                l = [a, b, c]
                l.sort()
                sum_n += gcd(gcd(l[0], l[1]), l[2])

    print(sum_n)

q3()

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
import math
count = 0
data = []
for i in range(num):
    for i2 in range(num):
        for i3 in range(num):
            temp = [i,i2,i3]
            temp.sort
            data.append(str(temp[0]) + str(temp[1]) + str(temp[2]))

kazu = list(set(data))

keisan = []

for i in kazu:
    count = 0
    for i2 in data:
        if i == i2:
            count += 1
    keisan.append([i,count])

count = 0
for i in keisan:
    count += math.gcd(math.gcd(int(i[0][0]) + 1,int(i[0][1]) + 1),int(i[0][2]) + 1) * int(i[1])
print(count)

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(1,k+1):
  for u in range(1,k+1):
    for y in range(1,k+1):
      ans+=gcd(i,u,y)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())

result = 0

for a in range(1, k+1):
  for b in range(1, k+1):
    for c in range(1, k+1):
      result += math.gcd(math.gcd(a, b), c)

print(result)

Submission status: Time Limit Exceeded

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

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

l = [i for i in range(1,K+1)]

result = []
[result.append(gcd(a,b,c)) for a,b,c in product(l,l,l)]
    
print(sum(np.asarray(result)))

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

def solve(k):
    import itertools
    pattern = itertools.product(range(1, k+1), repeat=3)

    count = 0
    for x in pattern:
        gcd = calc(x[0], x[1], x[2])
        count += gcd

    return count


k = int(input())

print(solve(k))

Submission status: Time Limit Exceeded

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

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

n = list(itertools.product(lis, repeat=3))
for i in range(len(n)):
    ma = math.gcd(math.gcd(n[i][0],n[i][1]),math.gcd(n[i][0],n[i][2]))
    a += ma

print(a)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
gcd_box = np.zeros((N,N,N),dtype = int)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

for i in range(1,N+1):
    i_div = make_divisors(i)
    for j_divisors in i_div:
        max_J = N // j_divisors
        for k in range(1,max_J+1):
            for l in range(1,max_J+1):
                gcd_box[i-1,k*j_divisors-1 ,l*j_divisors-1] = j_divisors
            
print(int(sum(sum(sum(gcd_box)))))

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
i=int(input())
sum=0
def gcd(*numbers):
    return reduce(math.gcd, numbers)
for a in range(1,i+1):
    for b in range(1,i+1):
        for c in range(1,i+1):
            sum+=gcd(a,b,c)
print(sum)

Submission status: Time Limit Exceeded

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

            sum = sum+gcd
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())
A = set()

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)


def function(K):
    list = []
    sum = 0
    for i in range(1,K+1):
        for j in range(1, K+1):
            list.append(gcd(i,j))
    return list

list = function(K)
sum = 0
new_list = []
for i in range(1,K+1):
    new_list+= [gcd(i,elm) for elm in list]


for i in new_list:
    sum += int(i)


print(sum)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

#最小公約数 ユークリッドの互除法
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

#最小公倍数
def lcm(self,a, b):
    return self.floor((a * b), self.gcd(a, b))

x = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for b in range(1,K+1):
            ij = gcd(i,j)
            x += gcd(ij,b)
            # print("pro {}".format(gcd(ij,b)))
print(x)

Submission status: Time Limit Exceeded

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


a=[1,1,1]
out=0
for j in range(1,input+1):
    a[2]=j
    a[0]=1
    a[1]=1
    for s in range(1,input+1):
        a[1]=s
        a[0]=1
        for k in range(1,input+1):
            a[0]=k
            ans = a[0]
            for i in range(1, 3):
                ans = math.gcd(ans, a[i])
            out=out+ans

print(out)

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations, combinations,combinations_with_replacement,product
import math
from functools import reduce

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

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

def main():
    #n, k = map(int,input().split())
    k = int(input())
    lists = []

    for i in range(k):
        lists.append(int(i+1))
        lists.append(int(i+1))
        lists.append(int(i+1))
    

    lists = list(combinations_with_replacement(lists,3))
    lists = sorted(set(lists))

        
    koubai = 0
    for i in lists:
        if len(set(i))==1:
            koubai = koubai + gcd(i[0],i[1],i[2])
            #print(koubai)
        elif len(set(i))==2:
            koubai = koubai + 3*gcd(i[0],i[1],i[2])
        else:
            koubai = koubai + 6*gcd(i[0],i[1],i[2])
            #print(koubai)
    print(koubai)
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
 
k = int(input())
klis = list(range(1,k+1))
lis = list(itertools.product(klis, klis, klis))
temp = []
for i in range(len(lis)):
    temp.append(math.gcd(math.gcd(lis[i][0],lis[i][1]),lis[i][2]))
 
print(sum(temp))

Submission status: Time Limit Exceeded

Solution code:
N = int(input()) + 1


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

    return x


ans = 0
for a in range(1, N):
    for b in range(1, N):
        gcd = a if a == b else find_gcd(a, b)

        for c in range(1, N):
            ans += c if gcd == c or a == b == c else find_gcd(gcd, c)

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
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):
            if j in l:
                if math.gcd(i,j)==1:
                    a+=K
                else:
                    a+=(K + (math.gcd(i,j)-1)*(K//j))
            else:
                for r in range(1,K+1):
                    a+=gcd(i,j,r)
print(a)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
def gcd(numbers):
    return reduce(fractions.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:
N = int(input()) + 1


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

    return x


ans = 0
for a in range(1, N):
    for b in range(1, N):
        if a == b:
            gcd = a
        else:
            gcd = find_gcd(a, b)
        for c in range(1, N):
            if gcd == c:
                ans += gcd
            else:
                new_gcd = find_gcd(gcd, c)
                ans += new_gcd

print(ans)

Submission status: Time Limit Exceeded

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

def gcdlist(*l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a

N = int(input())

I = range(1, N+1)
J = range(1, N+1)
K = range(1, N+1)

combinations = [(i, j, k)
                for i in I
                for j in J
                for k in K]

count = 0

for i, j, k in combinations:
    count = count + gcdlist(i, j, k)

print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
import copy


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

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


k=int(input())

sumsum=0

mapping=dict()


mapping = [[[0 for i in range(k+1)] for j in range(k+1)] for l in range(k+1)]
#print(mapping)

for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):

            ## a=gcd(i,j,l)
            ##sumsum+=a
            
            aa=[i,j,l]
            aa=sorted(aa)
            if mapping[aa[0]][aa[1]][aa[2]]!=0 :
                sumsum+=mapping[aa[0]][aa[1]][aa[2]]
            else:
                a=math.gcd(i,math.gcd(j,l))
                mapping[aa[0]][aa[1]][aa[2]]=a
                sumsum+=a
            
print(sumsum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

x,y,z = 0,0,0
gcds =[]
k = int(input())

for h in range(1,k+1):
  x = h
  for i in range(1,k+1):
    y = i
    for j in range(1,k+1):
      z = j
      #print(x,y,z)
      gcds.append(gcd(x,y,z))

print(sum(gcds))

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

total = 0
# 3つ同じ
for i in range(K):
  total += i+1

# 2つ同じ
for i in range(K-1):
  for j in range(i+1,K):
    if i+1 == 1:
      total += 1*6
    elif (j+1)%(i+1)==0:
      total += (i+1)*6
    else:
      tmp = 0
      for k in range(1,i+1):
        if (i+1)%k == 0 and (j+1)%k == 0:
          tmp = k
      total += tmp*6

# バラバラ
for i in range(K-2):
  for j in range(i+1,K-1):
    for k in range(j+1,K):
      if i+1 == 1:
        total += 1*6
      elif (j+1)%(i+1) == 0 and (k+1)%(i+1) == 0:
        total += (i+1)*6
      else:
        tmp = 0
        for l in range(1,i+1):
          if (i+1)%l == 0 and (j+1)%l == 0 and (k+1)%l == 0:
            tmp = l
        total += tmp*6
print(total)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
dp2 =np.zeros((n+1,n+1))

def gcd(x, y):
    x=int(x)
    y=int(y)
    if y == 0:
        return x
    else:
        if dp2[x,y]!=0:
            return dp2[x,y]
        else:
            dp2[x,y] = gcd(y, x % y) 
            return dp2[x,y]

def saidai(la):
    ans = la[0]
    for i in range(1, 3):
        ans = gcd(ans, la[i])
#        if dp2[ans,la[i]]==0:
#            ans = gcd(ans, la[i])
#            ans = int(ans)
#        else:
#            ans = dp2[ans,la[i]]
#            ans = int(ans)
    return ans




#dp = np.zeros((n,n,n))


an = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            an += saidai([i+1,j+1,k+1]) 
#                an += dp[l[0],l[1],l[2]]
            #print(i,j,k)
#            l = [i,j,k]
#            l.sort()
#            if dp[l[0],l[1],l[2]]!=0:
#                an += dp[l[0],l[1],l[2]]
#            else:
#                dp[l[0],l[1],l[2]] = saidai([l[0]+1,l[1]+1,l[2]+1]) 
#                an += dp[l[0],l[1],l[2]]
            #print(dp)
            #print('^^^^^^^^^^^^^^^^^^^^^^')

print(int(an))

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

k = int(input()) + 1


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


def counter(num):
    count = 0
    for a in range(1, num):
        for b in range(1, num):
            for c in range(1, num):
                count += gcd(a, b, c)
    print(count)

counter(k)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
import fractions
import itertools
sum_g=0
l=list(itertools.product([i for i in range(1,k+1)], repeat=3))
for p,q,r in l:
    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


k = int(input())

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

k += 1
ans = 0


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


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
import math

K = int(input())
sum = 0
kl = range(1, K+1)
combdict = {}

for i in kl:
    for j in kl:
        for k in kl:
            sum += math.gcd(i, math.gcd(j, k))
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
def gcd(a, b, c):
    z = min(a, b, c)
    for i in range(z, 0, -1):
        if a%i==0 and b%i==0 and c%i==0:
            return i

k = int(input())

d = {}

totsum = 0
for i in range(1, k+1):
    for j in range(i, k+1):
        for k in range(j, k+1):
            if i ==j ==k:
                totsum += i
                continue

            elif i==j or i==k or j==k: factor = 3
            else: factor = 6

            if i ==1 or j==1 or k==1: 
                totsum += 1*factor
                continue

            totsum += gcd(i, j, k)*factor

print(totsum)

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):
            gcd1 = int(math.gcd(a,b))
            gcd2 = int(math.gcd(b,c))
            gcd = int(math.gcd(gcd1,gcd2))

            sum = sum+gcd
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
from functools import reduce

def sangcd(i,j,k):
    return reduce(math.gcd, [i,j,k])

K = int(input())
Ans = 0
for i in itertools.product(range(1,K+1), repeat=3):
    Ans += sangcd(i[0],i[1],i[2])

print(Ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
a = int(input())
ans = 0
for i in range(1,a+1):
  for j in range(1,a+1):
    for k in range(1,a+1):
        # ans = ans + np.gcd.reduce([i, j, k])
        ans = ans + gcd(gcd(i, j),k)
print(ans)

Submission status: Time Limit Exceeded

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

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

print(C)

Submission status: Time Limit Exceeded

Solution code:
#C - Sum of gcd of Tuples (Easy)
K = int(input())
DP =[]
ans = 0
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)


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


for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            a = gcd_list([i, j, k])
            DP.append(a)

for l in range(len(DP)):
    ans += DP[l]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K = int(input())

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
n=int(input())
cc=0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            c1=gcd(i, j)
            c2=gcd(c1, k)
            cc+=c2
print(cc)

Submission status: Time Limit Exceeded

Solution code:
import fractions


from functools import reduce
K=int(input())

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


count=0
for i in range(1,K+1):
  for j in range(i,K+1):
    for k in range(j,K+1):
      if i==j and j==k and k==i:
        n=1
      elif i==j or j==k or k==i:
        n=3
      else:
        n=6
      count+=n*gcd_list([i,j,k])

print(count)

Submission status: Time Limit Exceeded

Solution code:


k=int(input())
 
import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
res=0
l= list(range(1,k+1))

for n in l:
    for i in l:
        for j in l:
            res+=gcd(n, i,j)
 
print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int( input() )

import math

Ans = 0
for a in range( 1 , N + 1 ):
    for b in range( 1 , N + 1 ):
        for c in range( 1 , N + 1 ):
            Ans += math.gcd(math.gcd(a,b),math.gcd(b,c))
print( Ans )

Submission status: Time Limit Exceeded

Solution code:
import itertools
import fractions
from functools import reduce
k = int(input())
num = []
for i in range(1, k+1):
    num.append(i)
    num.append(i)
    num.append(i)
permutation_num = list(itertools.permutations(num, 3))
s = set(permutation_num)
x = []
for j in s:
    y = reduce(fractions.gcd, j)
    x.append(y)

print(sum(x))

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
sum = 0
def gcb(x, y):
    if y == 0:
        return x
    else:
        return gcb(y,x%y)

for i in range(1, k + 1):
    for j in range(1, k + 1):
        

        for k in range(1, k + 1):
            sum += gcb(gcb(i, j), k)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from itertools import combinations_with_replacement, permutations

K = int(input())

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

num_list = []
combinations = list(combinations_with_replacement(range(1,K+1), 3))

for combi in combinations:
    permu = len(set(permutations(combi, 3)))
    gcd_num = three_gcd(*combi)
    num_list.append(gcd_num * permu)
    
print(sum(num_list))

Submission status: Time Limit Exceeded

Solution code:
import math
def tgcd(a,b,c):
    return math.gcd(a,math.gcd(b,c))
def T(N):
    s=0
    for i in range(1,N+1):
        for j in range(1,N+1):
            for l in range(1,N+1):
                s+=tgcd(i,j,l)
    return s
N=int(input())
print(T(N))

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

def sumGcd(n):
    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)
    return res

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

n = int(input())

res = sumGcd(n)
print(res)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))



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

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


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

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
sums = 0
sums += n*(n-1)*3 + 1

for k in range(2,n+1):
    for l in range(2,n+1):
        for p in range(2,n+1):
            sums += math.gcd(math.gcd(k,l),p)

print(sums)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
def gcd(X):
    return reduce(math.gcd, X)
K = int(input())
s = [gcd([i1, i2, i3]) for i1 in range(1, K+1) for i2 in range(1, K+1) for i3 in range(1, K+1)]
print(sum(s))

Submission status: Time Limit Exceeded

Solution code:

def q3():
    import math
    k = int(input())
    sum_n = 0
    gcd_2_dict = {}

    def gcd(n1, n2):
        key = tuple([n1, n2])
        if key in gcd_2_dict:
            return gcd_2_dict[key]
        gcd_num = math.gcd(n1, n2)
        gcd_2_dict[key] = gcd_num
        return gcd_num

    import time
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                l = [a, b, c]
                l.sort()
                sum_n += gcd(gcd(l[0], l[1]), l[2])

    print(sum_n)

q3()

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K=int(input())

i=1
r=0

while(i<K+1):
  j=1
  while(j<K+1):
    k=1
    while(k<K+1):
      if(i==1 or j==1 or k==1):
        r+=1
      elif(i==j and j==k):
        r+=i
      elif(i==j):
        r+=math.gcd(j,k)
      elif(j==k):
        r+=math.gcd(i,j)
      elif(i==k):
        r+=math.gcd(i,j)
      else:
        r+=gcd(i, j, k)
      k+=1
    j+=1
  i+=1

print(r)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
k=int(input())
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1,k+1):
        a=(i,j,l)
        if len(a)==1:
            ans=ans+i
        elif len(a)==2:
            ans=ans+gcd(a[0],a[1])
        else:
            ans=ans+gcd(a[0],gcd(a[1],a[2]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math

k=200
klis = list(range(1,k+1))
lis = list(itertools.product(klis, klis, klis))
temp = []
for i in range(len(lis)):
    temp.append(math.gcd(math.gcd(lis[i][0],lis[i][1]),lis[i][2]))

print(sum(temp))

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

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):
            gcd1 = int(math.gcd(a,b))
            gcd2 = int(math.gcd(b,c))
            
            #print(gcd1,gcd2)
            gcd = gcd1 = int(math.gcd(gcd1,gcd2))

            sum = sum+gcd
print(sum)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

import math
from functools import reduce

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

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python

import sys
import numpy as np

gcd_arr = {}

def gcd(a, b, c):
    key = tuple(sorted([a, b, c]))
    if key in gcd_arr:
        return gcd_arr[key]
    ret = 1
    while True:
        m = min(a, b, c)
        if m == 1:
            break

        can_div = False
        for i in range(2, m+1):
            if (a % i) == 0 and (b % i) == 0 and (c % i) == 0:
                a = a // i
                b = b // i
                c = c // i
                ret *= i
                can_div = True
                break

        if not can_div:
            break
    gcd_arr[key] = ret
    return ret

K = int(sys.stdin.readline())

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)