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

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
def gcd2(a, b, c):
	aa = math.gcd(a,b)
	return math.gcd(aa,c)

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

Submission status: Time Limit Exceeded

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


K = int(input())

G = [[0] * (K + 1) for _ in range(K + 1)]

for a in range(1, K + 1):
    for b in range(1, K + 1):
        G[a][b] = gcd(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):
            if G[a][b] == 1:
                ans += 1
                continue
            ans += gcd(G[a][b], c)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())
res=0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            #print(a,b,c)
            tmp = (math.gcd(math.gcd(a,b),c))
            res += tmp
print(res)

Submission status: Time Limit Exceeded

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

import math
from functools import reduce

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

for i in range(1, N):

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

print( sum )

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

Submission status: Time Limit Exceeded

Solution code:
import math


N = int(input())

N_i = N
N_j = N
N_k = N

# def 

list = []
for i in range(N_i):
    for j in range(N_j):
        m = math.gcd(i+1,j+1)
        for k in range(N_k):
            list_2 = [i+1,j+1,k+1]
            # print(str(list_2))
            if m == 1:
                list.append(1)
                # print("m-1!")
            else:
                m_1 = math.gcd(k+1,i+1)
                m_2 = math.gcd(k+1,j+1)
                if m_1 == 1 or m_2== 1:
                    list.append(1)
                #     print("1!")
                else:
                    list.append(math.gcd(m_1,m_2))

result = 0
for l in list:
    result += int(l)

print(str(result))

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
 
def gcd_list(a,b,c):
    return reduce(math.gcd, [a,b,c])
 
n = int(input())
cnt = 0
for i in range(1,n + 1):
    for j in range(1,n + 1):
        for k in range(1,n + 1):
            
            cnt += gcd_list(i,j,k)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import math
from functools import reduce

def solve(K: int):
    K += 1
    ans = []
    for i in range(1, K):
        for j in range(1, K):
            for k in range(1, K):
                ans.append(gcd(i, gcd(j, k)))
    print(sum(ans))
    return

def gcd(x: int, y: int):
    """xとyの最大公約数を求める"""
    return gcd(y, x % y) if y else x
    
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())

def exit():
    import sys
    sys.exit(0)


def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))


d = dict()
d2 = dict()

def check(a, b, d2):
    t = tuple(sorted([a,b]))
    if t in d2:
        return d2[t]
    return False

k = load()
s = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1, k+1):
            r = check(i, j, d2)
            target = None
            if r:
                target = k
            else:
                r = check(j, k, d2)
                if r:
                    target = i
                else:
                    r = check(i, k, d2)
                    if r:
                        target = j
                    else:
                        # print(i,j,k)
                        d2[(i,j)] = gcd(i,j)
                        r = d2[(i,j)]
                        target = k
            r2 = check(r, target, d2)
            if r2:
                s += r2
            else:
                d2[(r, target)] = gcd(r, target)
                s += d2[(r, target)]

print(s)

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

Submission status: Time Limit Exceeded

Solution code:

K=int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

k = int(input())
ans = 0

for i in range(1, k+1):
    for j in range(1,k+1):
        tmp = gcd(i,j)
        for m in range (1,k+1):
            ans += gcd(tmp,m)

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

print(ans)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
 
K = int(input())
 
import math
answer = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            gcd = math.gcd(math.gcd(i, j), k)
            answer += gcd
 
print(answer)

Submission status: Time Limit Exceeded

Solution code:
#test.py
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 j in range(1,K+1):
        for k in range(1,K+1):
                ans += gcd(i,j,k)

print(ans)
#メモ化再帰で高速化できないか考える
# Kまでの数の組み合わせを考える

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

g2 = [[0]*(K+1) for _ in range(K+1)]
def gcd(a, b):
    if g2[a][b] > 0:
        return g2[a][b]
    tmpa = a
    tmpb = b
    while b > 0:
        a,b = b, a%b
    g2[tmpa][tmpb] = a
    g2[tmpb][tmpa] = a
    return a

def gcd_3(a,b,c):
    g = gcd(a,b)
    g = gcd(g,c)
    return g

sm = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            sm += gcd_3(a,b,c)

print(sm)

Submission status: Time Limit Exceeded

Solution code:
import math
if __name__ == '__main__':
    k = int(input())
    ans = 0
    for i in range(1, k + 1):
        for j in range(1, k + 1):
            for y in range(1, k + 1):
                ans += math.gcd( math.gcd(j, y),i)

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import fractions

def main():
    import math
    k = int(input())
    ans = 0

    for i in range(1,k+1):
        for j in range(1,k+1):
            for l in range(1,k+1):
                ans += reduce(lambda a,b: fractions.gcd(a, b), [i,j,l])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

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

print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
if __name__ == '__main__':
    k = int(input())
    ans = 0
    for i in range(1, k + 1):
        for j in range(1, k + 1):
            for y in range(1, k + 1):
                ans += math.gcd(i, math.gcd(j, y))

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import *

K = int(input())

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
k=int(input())
s=0
for x in range(1,k+1):
	for y in range(1,k+1):
		for z in range(1,k+1):
			s+=np.gcd.reduce([x,y,z])
print(s)

Submission status: Time Limit Exceeded

Solution code:
import sys; sys.setrecursionlimit(2147483647); input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log
from collections import Counter, defaultdict, deque
from operator import itemgetter
INF = float('inf'); MOD = 10**9+7
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(MI())
def LIR(n): return [LI() for i in range(n)]
def IS(): return input().rstrip()
def gcd_core(a, b):
    if b == 0: return a
    else: return gcd_core(b, a % b)
def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)): g = gcd_core(g, arr[i])
    return g
def main():
    K = I()
    for a in range(1, K+1):
        for b in range(a, K+1):
            for c in range(b, K+1):
                x = len({a, b, c})
                yield gcd([a, b, c])*sum([i for i in range(1, x+1)])
if __name__ == '__main__':
    print(sum(main()))

Submission status: Time Limit Exceeded

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

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

k = int(input())

a = product([int(i) for i in range(1,k+1)], repeat=3)
ans = 0

for i in list(a):
  ans += gcd1(i[0], i[1], i[2])

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for p in range(1, k+1):
    for q in range(1, k+1):
        for r in range(1, k+1):
            ans += math.gcd(math.gcd(p, q), r)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def GCD(y,x):
    if y>x:
        p,q=y,x
    else:
        p,q=x,y
    if p%q==0:
        return q
    else:
        return GCD(q,p%q)

ans1=0

K=int(input())
for i in range(1,K+1):
    for j in range(1,K+1):
        for l in range(1,K+1):
            ans1+=GCD(GCD(i,j),l)

print(ans1)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
K = int(input())
list_gcd = list(itertools.product(range(1, K+1), repeat=3))
result = 0
for i in range(K * K * K):
    result += gcd(*list_gcd[i])
print(result)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:

k=int(input())
ans=0

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

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

sumlis={}
for a in range(1,k+1):
    for b in range(1,k+1):
        t=gcd(a,b)
        for c in range(1,k+1):
            ans+=gcd(t,c)
                
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

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(gcd(i,j),k)
print(res)

Submission status: Time Limit Exceeded

Solution code:
def euc(i, j):
    if i > j:
        i, j = j, i
    while j%i != 0:
        k = abs(j - i)
        if k > i:
            i, k = k, i
        j = i%k
        if j == 0:
            return(k)
        i = k
        if i > j:
            i, j = j, i
    return i


N = int(input())
sum = 0
for i in range(1, N + 1):
    for j in range(1, N + 1): 
        ij = euc(i, j)
        for k in range(1, N + 1):
            sum += euc(ij, k)
print(sum)

#print(euc(2, 3))

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

k=int(input())
count = 0

for i in range(1,k+1):
    for j in range(i,k+1):
        for l in range(j,k+1):
            if i==j and j==l:
                count += i
            elif i==j:
                x = gcd(i,l)
                count += x*3
            elif j==l:
                x = gcd(i,l)
                count += x*3
            elif l==i:
                x = gcd(i,j)
                count += x*3 
            else:
                x = gcd(i,j)
                x = gcd(x,l)
                count += x*6

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
from fractions import gcd
from itertools import combinations
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

K = int(read())
ans = 0

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for 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())
 
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:
from math import gcd

k = int(input())

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

print(sum)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
 
K = int(input())
 
res = 0
tmp = 0
d = []
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            if i == j and j == k:
                res += i
            elif i == j:
                res += gcd(i,k)
            elif i == k:
                res += gcd(j,k)
            elif j == k:
                res += gcd(i,j)
            else:
                res += gcd(gcd(i,j),k)
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

# def GCD(a,N):
#     gcd = a[0]
#     for i in range(1, N):
#         gcd = math.gcd(gcd, a[i])
#     return gcd


k = int(input())

ans = 0
L = []
G = [0] * k**3

for i in range(1, k+1):
    for j in range(1, k+1):
        for l in range(1, k+1):
            # _l = sorted([i,j,l])
            # if i==1 or j == 1 or l == 1:
            #     ans += 1
            # elif not _l in L:
            #     L.append(_l)
            #     g = GCD(_l, 3)
            #     G[L.index(_l)] = g
            #     ans += g
            # else:
            #     ans += G[L.index(_l)]
            ans += gcd(i,gcd(j,l))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# Python3 code to demonstrate working of 
# All possible N combination tuples 
# Using product() 
from itertools import product 
from fractions import gcd
from functools import reduce

def find_gcd(list):
    x = reduce(gcd, list)
    return x
# initialize N 
N = int(input())
sum=0
# All possible N combination tuples 
# Using product() 
res = list(product(range(1, N + 1), repeat = 3)) 

for i in res:
    sum=sum+find_gcd(list(i))

# printing result 
print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import fractions
k = int(input())
ans = k**3 - (k-1)**3
for a in range(2,k+1):
  for b in range(2,k+1):
    for c in range(2,k+1):
      ans += fractions.gcd(a, fractions.gcd(b, c))
print(ans)

Submission status: Time Limit Exceeded

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

k = int(input())

total = 0
ran = range(1, k + 1)
for i, j, k in itertools.product(ran, ran, ran):
    total += math.gcd(math.gcd(i, j), k)
    
print(total)

Submission status: Time Limit Exceeded

Solution code:
import copy
K=int(input())
primes=[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,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199]
yakusuu_array=[]
for i in range(200):
  i+=1
  tmp=[]
  while i!=1:
    for prime in primes:
      if i % prime ==0:
        tmp.append(prime)
        i//=prime
  yakusuu_array.append(tmp)


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

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

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

def main():
    K = int(input())
    l = []
    for i in range(1, K+1, 1):
        for j in range(1, K+1, 1):
            for k in range(1, K+1, 1):
                g = gcd(i, j, k)
                l.append(g)            
    print(sum(l))
main()

Submission status: Time Limit Exceeded

Solution code:
import sys, os, math

def get_cd(n):
    cd = []
    for i in range(1, int(n/2)+1):
        if n % i == 0:
            cd.append(i)
        else:
            continue
    cd.append(n)
    return cd

def get_gcd(a, b, c, cd_d):
    if 1 in [a, b, c]:
        return 1
    else:
        min_v = min([a,b,c])
        cds_min = cd_d[min_v]
        gcd = 1
        cd = sorted(list(set(cd_d[a]) & set(cd_d[b]) & set(cd_d[c])))
        return cd[-1]

if __name__ == '__main__':
    k = int(input())
    cc_d = {}
    for i in range(1, k+1):
        cc_d[i] = get_cd(i)

    computed_d = {}
    s = 0
    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:
                    s += a
                else:
                    gcd = get_gcd(a, b, c, cc_d)
                    if a != b != c:
                        s += gcd*6
                    else:
                        s += gcd*3
    print(s)

Submission status: Time Limit Exceeded

Solution code:
#import fractions
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 get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

def main():
    #n, k = map(int,input().split())
    k = int(input())
    lists = []
    #for i in range(k):
    #    for j in range(k):
    #        for l in range(k):
    #            lists.append((i+1,j+1,l+1))
    for i in range(k):
        lists.append(int(i+1))
        lists.append(int(i+1))
        lists.append(int(i+1))
    
    #for v in combinations_with_replacement(lists,3):
    #    print(v)
    lists = list(combinations_with_replacement(lists,3))
    lists = set(lists)
    #print(lists)
    #lists2 = [i[0]*100+i[1]*10+i[2] for i in lists]
    #print(lists2)
        
    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()


"""
    grid.append(array)
#print(grid)

for i in grid:
    if len(i)==1:
        s = ''.join(list(reversed(s)))
    else:
        if i[1]=="1":
            s = i[2]+s
        else:
            s = s+i[2]
print(s)

a = array[0]
b = array[1]

min8 = a/0.08
max8 = (a+1)/0.08
min10 = b/0.1
max10 = (b+1)/0.1

def lists(a,b):
    if a%1==0:
        a2 = a
    else:
        a2 = int(a)+1
    if b%1==0:
        b2 = b-1
    else:
        b2 = int(b)
    return np.arange(a2,b2+1)

list8 = lists(min8,max8)
list10 = lists(min10,max10)
#print(list8,list10)
hosii = list(set(list8)&set(list10))
if len(hosii)>0:
    print(int(np.min(hosii)))
else:
    print(-1)


grid = np.array(grid)

N = int(input())
s = [int(input()) for i in range(N)]

for i in s:
    grid = np.where(grid==i,0,grid)
    
print(grid)
    
if grid[0][0]==0 and grid[0][1]==0 and grid[0][2]==0:
    han = "Yes"
elif grid[1][0]==0 and grid[1][1]==0 and grid[1][2]==0:
    han = "Yes"
elif grid[2][0]==0 and grid[2][1]==0 and grid[2][2]==0:
    han = "Yes"
elif grid[0][0]==0 and grid[1][0]==0 and grid[2][0]==0:
    han = "Yes"
elif grid[0][1]==0 and grid[1][1]==0 and grid[2][1]==0:
    han = "Yes"
elif grid[0][2]==0 and grid[1][2]==0 and grid[2][2]==0:
    han = "Yes"
elif grid[0][0]==0 and grid[1][1]==0 and grid[2][2]==0:
    han = "Yes"
elif grid[0][2]==0 and grid[1][1]==0 and grid[2][0]==0:
    han = "Yes"
else:
    han = "No"
print(han)
"""

Submission status: Time Limit Exceeded

Solution code:
memo = {}

def gcd(a, b):
    global memo

    ia = max(a, b)
    ib = min(a, b)

    if (ia, ib) in memo:
        return memo[(ia, ib)]

    while b != 0:
        t = b
        b = a % b
        a = t
    
    memo[(ia, ib)] = a    
    return a

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

K = int(input())
total = 0

# 3 scenarios
# X-X-X
# X-X-Y
# X-Y-Z

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

        
print(total)
#total += sum(range(1, 201))
#print(total + sum(range(1,201)))
#print("diff", 10813692-total)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools

K = int(input().split()[0])

def gcd_args(i, j, k):
    return math.gcd(math.gcd(i, j), k)

ans = 0
for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            tmp_ans = gcd_args(i, j, k)
            l = [i, j, k]
            c = set()
            for v in itertools.permutations(l, 3):
                c.add(v)

            ans += tmp_ans * len(c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

import math
result=0
for i in range(1,n+1):
    for ii in range(1,n+1):
        for iii in range(1,n+1):
            temp=math.gcd(i,ii)
            result+=math.gcd(temp,iii)
print(result)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K = int(input())

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

def threegcd(a,b,c):
  num1 = math.gcd(a,b)
  num2 = math.gcd(num1,c)
  return num2

inputno = int(input())
sum = 0
for a in range(inputno):
  a += 1
  for b in range(inputno):
    b += 1
    for c in range(inputno):
      c += 1
      sum += threegcd(a,b,c)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
def gcd(a,b,c):
    if min(a,b,c) == 1:
        return 1

    arr = []
    for i in range(2, min(a,b,c)+1):
        if a%i == b%i == c%i == 0:
            cnt = 0
            while a%i == b%i == c%i == 0:
                cnt += 1
                a //= i
                b //= i
                c //= i
            arr.append([i, cnt])

    if a==b==c and a!=1:
        arr.append([a, 1])

    ans = 1
    for i in range(len(arr)):
        ans *= arr[i][0]**arr[i][1]
    return ans

Ans = 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:
                Ans+=gcd(i,j,k)
            elif len({i,j,k}) == 2:
                Ans+=gcd(i,j,k)*3
            else:
                Ans+=gcd(i,j,k)*6
print(Ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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


k = int(input())
ans = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for m in range(1, k+1):
#             l = list(i, j, m)
            res =gcd_(i, j, m)
            ans += res
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
from functools import reduce

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

K = int(input())
A = []
B = 0
C = 0

for i in range (K+1):
    A.append(i)
A.remove(0)
 
sum = list(itertools.product(A, repeat=3))

for i in range(len(sum)):
    B = gcd(*sum[i])
    C += B

print(C)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

# メモ用
memo = np.zeros((201,201,201))
K = int(input())

count = 0

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

def gcd3(a,b,c):
    # 〇順に並べる
    # L = [a,b,c]
    # L.sort()
    # a,b,c = L[0],L[1],L[2]
    

    if memo[a,b,c] != 0:
        return memo[a,b,c]
    else:
        t = gcd(a,b)
        memo[a,b,c] = gcd(t,c) 
        return memo[a,b,c]


for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            count += gcd3(i,j,k)

print(int(count))

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 = set(itertools.permutations(num, 3))
x = []
for j in permutation_num:
    y = reduce(fractions.gcd, j)
    x.append(y)

print(sum(x))

Submission status: Time Limit Exceeded

Solution code:
import copy
K=200
primes=[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,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199]
yakusuu_array=[]
for i in range(200):
  i+=1
  tmp=[]
  while i!=1:
    for prime in primes:
      if i % prime ==0:
        tmp.append(prime)
        i//=prime
  yakusuu_array.append(tmp)


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

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

Submission status: Time Limit Exceeded

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

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