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 sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
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))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))




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

import fractions,itertools
data = [i for i in range(1,K+1)]

import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
ans = 0
for a,b,c in itertools.product(data, repeat=3):
    ans += gcd(a,b,c)
print(ans)

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,y,z in L:
    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:
from functools import reduce
import functools
import fractions
 
@functools.lru_cache(maxsize=12800)
def gcd(*numbers):
  return reduce(gcd_, numbers)
  # return reduce(fractions.gcd, numbers)

@functools.lru_cache(maxsize=12800)
def gcd_(a, b):
  if (b == 0):
    return a
  return gcd(b, a % b)
 
sum = 0
K = int(input())
 
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      sum += gcd(i,j,k)
      
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
import itertools as itr

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

n = int(input()) 
aa = list(range(1, n+1 ))
bb = list(range(1, n+1))

cc = list(range(1, n+1))

def word_edit(word_list):
    new_words = []
    for word in word_list:
        new_word = str(word).lower()
        new_words.append(new_word)

    return new_words

sum1 = 0
for a in word_edit(aa):
    for b in word_edit(bb):
        for c in word_edit(cc):
            sum1+= gcd(int(a),int(b),int(c))
print(sum1)

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce


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


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


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

    test = [gcd(i, j, k) for i in range(1, K + 1) for j in range(1, K + 1) for k in range(1, K + 1)]
    print(sum(test))


if __name__ == '__main__':
    main()

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

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)) * 3
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 + l4

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

k = int(input())

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

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce


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


def gcd(num):
    return reduce(euclid, num)


k = int(input())
ans = 0
i_list = []

for i1 in range(1, k+1):
    for i2 in range(1, k+1):
        for i3 in range(1, k+1):
            ans += gcd([i1, i2, i3])

print(ans)

Submission status: Time Limit Exceeded

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

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

sum = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            sum += gcdWithThreeArgs(a, b, c)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
n = int(input())
ans = 0
for i in range (1, n+1):
  for j in range (1, n+1):
    gcd1 = gcd(i,j)
    
    for k in range (1, n+1):
      
      gcdf  = gcd(gcd1,k)
      ans = ans+gcdf
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
k = int(input())+1
out = 0
for i in range(1,k):
    for i2 in range(1,k):
        a = np.gcd(i,i2)
        for i3 in range(1,k):
            out += np.gcd(a,i3)
print(out)

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

n = int(input())

cnt = 0

for i in range(n):
    i +=1
    for j in range(n):
        j +=1
        for k in range(n):
            k +=1

            cnt += gcd(i,j,k)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
from functools import reduce

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

a = int(input())
list_a = [i for i in range(1, a + 1)]
res = 0
kumi = list(itertools.product(list_a, repeat=3))
for i in kumi:
    ans = gcd_list(i)
    res += ans

print(res)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

k = int(input())

seq = []
ran = range(1, k + 1)
for i in ran:
    for j in ran:
        for k in ran:
            n = reduce(lambda x, y: math.gcd(x, y), (i, j, k))
            seq.append(n)

print(sum(seq))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
import itertools

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

a = int(input())

ans = 0
for i in range(1, a+1):
    for k in range(1, a+1):
        for j in range(1, a+1):
            ans += int(gcd(i, k, j))
            # print(math.gcd(i, k ,j))

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

K = int(input())

number = [i for i in range(1, K+1)]
comb = list(product(number, repeat=3))

amount = 0
for a, b, c in comb:
    if a <= b <= c:
        if a == b and b == c:
            amount += a
        elif a == b or b == c:
            count = gcd(a, c)
            amount += count * 3
        else:
            a_k, b_k, c_k = a, b, c
            count = gcd(a, b, c)
            amount += count * 6

print(amount)

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input().rstrip())


ans = 0
for a in range(1, k + 1):
    if a == 1:
        ans += k * k
    else:
       for b in range(1, k + 1):
            if b == 1:
               ans += k
            else:
                for c in range(1, k + 1):
                    if c == 1:
                        ans += 1
                    else:
                        if a == b:
                            ans += math.gcd(a, c)
                        elif a == c:
                            ans += math.gcd(b, c)
                        else:
                            tmp = math.gcd(a, b)
                            ans += math.gcd(tmp, c)

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 gcd_list(numbers):
    return reduce(math.gcd, numbers)

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

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
k = int(input())
s = 0

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

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,c)
      # print(str(a) + "," + str(b) + "," + str(c))

print(s)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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


K = int(input())

ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

s = 0

N = int(input())
for a in range(N):
	for b in range(N):
		for c in range(N):
			#print(a+1,b+1,c+1)
			if a+1 == 1 or b+1 == 1 or c+1 == 1:
				s += 1
			elif (a+1 != 1 & a+1 == 2) or (b+1 != 1 & b+1 == 2) or (c+1 != 1 & c+1 == 2):
				s += 2
			else:
				s += gcd(a+1, b+1, c+1)
			#print(s)
print(s)

Submission status: Time Limit Exceeded

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

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

ans=k*(k+1)//2
l = [int(i) for i in range(1,k+1)]
for i in itertools.combinations(l,3):
    ans += fractions.gcd(fractions.gcd(i[0],i[1]),i[2])*6

for i in itertools.combinations(l,2):
    ans += fractions.gcd(i[0],i[1])*6

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
num = int(input())
sum = 0
for i in range(1, num+1):
  for j in range(1, num+1):
    for k in range(1, num+1):
      if i > j or j > k:
        continue;
      else:
        temp = fractions.gcd(i, j)
        if i != j and j != k:
          sum += (fractions.gcd(temp, k)) * 6
        elif i == j and j != k:
          sum += (fractions.gcd(temp, k)) * 3
        elif i != j and j == k:
          sum += (fractions.gcd(temp, k)) * 3
        else:
          sum += fractions.gcd(temp, k)
print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from itertools import combinations_with_replacement

def main():
    k = int(input())
    res = 0
    for c in combinations_with_replacement(range(1,k+1), 3):
        tmp = np.gcd.reduce(c)
        l = len(set(c))
        mul = 1
        if l == 2:
            mul = 3
        elif l == 3:
            mul = 6
        res += tmp * mul
    print(res)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
import itertools


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

x = int(input())
_sum = [gcd(*i) for i in itertools.product(range(1, x+1), repeat=3)]
print(sum(_sum))

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import gcd, ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
c = 0
K = INT()
ans = 0

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




exit()
dic = defaultdict(int)
for i in range(1, K+1):
    for j in range(1, K+1):
        if i <= j:
            dic[i] += 1
        else:
            dic[j] += 1
        # ans += gcd(i, j)
print(dic)
ans = 0

# for i in range(1, K):
for key, value in dic.items():
    ans += (K-key+1) * value
#         if key <= i:
#             ans += value
#         else:
#             ans += key
print(ans)
            
    
# ans += 1 * (K ** 3)
# for i in range()
# ans += 
# print(ans)

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


# for i in range(1, K+1):
#     for j in range(1, K+1):
#         a = gcd(i, j)

#         for k in range(1, K+1):
#             b = gcd(k, a)
#             # print(a, b)
#             c += b
#         # for k in range(1, K):
#         #     print(gcd(i, j, k))
#         #     c += gcd(i, j, k)
# print(c)

Submission status: Time Limit Exceeded

Solution code:
import math
k = int(input())
mat = [[None]*(k+1) for _ in range(k+1)]
def gcd(x,y,mat=mat):
  if x>y: x,y = y,x
  if not mat[x][y]:
    mat[x][y] = math.gcd(x,y)
  return mat[x][y]

memo = [[[None]*(k+1) for i in range(k+1)] for j in range(k+1)]

ans = 0
for p in range(1,k+1):
  for q in range(1,k+1):
    for r in range(1,k+1):
      a = sorted([p,q,r])
      if memo[a[0]][a[1]][a[2]] == None:
        memo[a[0]][a[1]][a[2]] = gcd(p,gcd(q,r))
      ans += memo[a[0]][a[1]][a[2]]
      
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools

K = int(input())
l_p = list(itertools.product(range(1, K+1), range(1, K+1), range(1, K+1)))
answer = 0

for x in l_p:
    temp = math.gcd(x[0], x[1])
    answer += math.gcd(x[2], temp)

print(answer)

Submission status: Time Limit Exceeded

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


k = int(input())
# h, w = map(int, input().split())
# a = list(map(int, input().split()))
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 not _l in L:
                L.append(_l.sort())
                g = GCD(_l, 3)
                G[L.index(_l.sort())] = g
                ans += g
            else:
                ans += G[L.index(_l.sort())]
            # ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans = 0
N = int(input())
L = []
for x in range(1,N+1):
    for y in range(1,N+1):
       L.append(gcd(x,y))
for x in L:
    for z in range(1,N+1):
        ans += gcd(x,z)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

K = int(input())

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

output = 0

for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      output += gcd_list([a, b, c])

print(output)

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

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

print(int(result))

Submission status: Time Limit Exceeded

Solution code:
K=int(input())

import fractions,itertools
data = [i for i in range(1,K+1)]


ans = 0
for trip in itertools.product(data, repeat=3):
    ans_ = trip[0]
    for i in range(1, 3):
        ans_ = fractions.gcd(ans_, trip[i])
    ans += ans_
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
import itertools
import functools
import math
l = list(range(1,n+1))
counter = 0
for v in itertools.product(l, repeat=3):
    gcd = functools.reduce(math.gcd, v)
    counter+=gcd
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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


k = int(input())
A=list()

for i in range(1,k+1):
  for j in range(1,k+1):
    for k in range(1,k+1):
        a=(gcd(i,j,k))
        A.append(a)
print(sum(A))

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

Submission status: Time Limit Exceeded

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

for i in range(k):
  for j in range(k):
    for l in range(k):
      c=math.gcd(i+1,j+1)
      s+=math.gcd(c,l+1)
      
print(s)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
K = int(input())
A = B = C = [i for i in range(1, K+1)]
cnt = sum([gcd(gcd(a,b),c) for a in A for b in B for c in C])   
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
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(n):
	for j in range(n):
		for k in range(n):
			ans+=gcd(i+1,j+1,k+1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

sets = dict()

def gcd2(a, b):
    if a > b:
        key = (b, a)
    else:
        key = (a, b)
    
    if key in sets.keys():
        # print("cached")
        return sets[key]
    else:
        # print("stored")
        ans = math.gcd(a, b)
        sets[key] = ans
        return ans

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

n = int(input())

ans = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            ans += gcd3(i, j, k)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K = int(input())
B = list()
a = int()
b = int()
c = int()
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

K = int(input())

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

answer = 0
#for a in range(1,K+1):
#    for b in range(1,K+1):
#        for c in range(1,K+1):
#            lis = [a,b,c]
#            temp = gcd(lis)
##            print(temp)
#            answer += temp
list1 = [[c, b, a] for c in range(1,K+1) for b in range(1,K+1) for a in range(1,K+1) ]            
#print(list1)
#print(list1[0])
for i in range(len(list1)):
    temp = gcd(list1[i])
#    print(temp)
    answer += temp
print(answer)

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 config in list(product(range(1, k+1), range(1, k+1), range(1, k+1))):
    a, b, c = config
    if a==1 or b==1 or c==1: 
        totsum+=1
    elif a==b==c:
        totsum+=a
    else:
        try :
            ans = d[tuple(sorted((a, b, c)))]
        except: 
            ans = gcd(a, b, c)
            d[tuple(sorted((a, b, c)))] = ans

        totsum += ans
# print(d)
print(totsum)

Submission status: Time Limit Exceeded

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

def GCD(a,b,c):
    return (gcd(gcd(a,b),gcd(a,c)))
s=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:
                s=s+GCD(i,j,k)
            elif i==j and j!=k:
                s=s+GCD(i,j,k)*3
            elif i!=j and j==k:
                s=s+GCD(i,j,k)*3
            else:
                s=s+GCD(i,j,k)*6
print (s)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
 
N  = int(input())
sum = 0
 
import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
for i in range (N):
    for j in range(N):
        for k in range(N):
            sum += gcd(*[i+1, j+1, k+1])
 
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd 
from functools import reduce
import itertools
k = int(input())
a = [i for i in range(1,k+1)]
s =0
#同じ数字３つの時
s = int(k*(k+1)/2)
#同じ数字２つと違う数字一つ
for q in itertools.combinations(a,2):
  s += reduce(gcd,q)*3*2
for t in itertools.combinations(a,3):
  s += reduce(gcd,t)*6
print(s)

Submission status: Time Limit Exceeded

Solution code:
import fractions
N=int(input())
ans=0
GCD=1
for i in range(1,N+1):
  for j in range(1,N+1):
    GCD=fractions.gcd(i,j)
    for n in range(1,N+1):
      ans+=fractions.gcd(GCD,n)

print(ans)

Submission status: Time Limit Exceeded

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

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

a = 0
for i in list:
	for k in list:
		for l in list:
			a += gcd(i,k,l)
print(a)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import functools
import fractions
 
@functools.lru_cache(maxsize=128)
def gcd(*numbers):
  return reduce(gcd_, numbers)
  # return reduce(fractions.gcd, numbers)

@functools.lru_cache(maxsize=128)
def gcd_(a, b):
  if (b == 0):
    return a
  return gcd(b, a % b)
 
sum = 0
K = int(input())
 
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      sum += gcd(i,j,k)
      
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
i = int(input())

def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans = 0
for i1 in range(1,i+1):
    for i2 in range(1,i+1):
        for i3 in range(1,i+1):
            num = gcd(i1,i2,i3)
            ans += num
print(ans)

Submission status: Time Limit Exceeded

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

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

sum = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            sum += gcdWithThreeArgs(a, b, c)
print(sum)

Submission status: Time Limit Exceeded

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


n=int(input())
sum2=0
for p in range(1,n+1):
    for q in range(1,n+1):
        for r in range(1,n+1):
            sum2=sum2+gcd(p,gcd(q,r))
print(sum2)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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


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

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

la = []
l = list(range(1, k+1))
for a, b, c in itertools.product(l, l, l):
    la.append(gcd(a, b, c))

print(sum(la))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
k = int(input())+1
out = 0
for i in range(1,k):
    for i2 in range(1,k):
        for i3 in range(1,k):
            out += np.gcd(np.gcd(i,i2),i3)
print(out)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())


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


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

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools

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

num = int(input())

arr = list(range(1, num + 1))
# # 3種の数字
# tri = itertools.combinations(arr, 3)
# sum_tri = sum([gcd(t[0], t[1], t[2]) for t in tri])
# # 2種の数字
# di = itertools.combinations(arr, 2)
# sum_di = 6 * sum([math.gcd(d[0], d[1]) for d in di])
# # 1種
# single = sum(arr)
# print(sum_tri + sum_di + single)
print(sum([sum([sum([gcd(a, b, c) for c in arr]) for b in arr]) for a in arr]))

Submission status: Time Limit Exceeded

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

print(m)