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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

ans = l2 + l3 + l4

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def u(a,b):
  if(a<b):
    z = b
    b = a
    a = z
  r = a % b
  while(r!=0):
    a = b
    b = r
    r = a % b
  return b
 
l = int(input())
s = 0
for i in range(1,l+1):
  for i2 in range(1,l+1):
    z = u(i,i2)
    for i3 in range(1,l+1):
      z2 = u(z,i3)
      s+=z2
print (s)

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
#k = 3

class GCD:
    def __init__(self):
        self.cache = {}
        self.cache3 = {}
    def gcd2(self, a, b):
        a, b = sorted([a, b], reverse=True)
        if (a in self.cache and b in self.cache[a]):
            return self.cache[a][b]
        if (a % b == 0):
            if (a not in self.cache):
                self.cache[a] = {}
            self.cache[a][b] = b
            return b
        return self.gcd2(b, a % b)
    def gcd3(self, a, b, c):
        a, b, c = sorted([a, b, c], reverse=True)
        if (a in self.cache3 and b in self.cache3[a] and c in self.cache3[a][b]):
            return self.cache3[a][b][c]
        if (a not in self.cache3):
            self.cache3[a] = {}
        if (b not in self.cache3[a]):
            self.cache3[a][b] = {}
        result = self.gcd2(self.gcd2(a, b), c)
        self.cache3[a][b][c] = result
        return result

a = 1
b = 1
c = 1
result = 0
client = GCD()
while (a <= k):
    b = 1
    while (b <= k):
        c = 1
        while (c <= k):
            result += client.gcd3(a, b, c)
            c += 1
        b += 1
    a += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
import fractions

K = input()

Sum = 0
k = int(K)

for A in range(k):
    a = A + 1
    for B in range(k):
        b = B + 1
        gcd_ab = fractions.gcd(a, b)
        for C in range(k):
            c = C + 1

            Sum = Sum + fractions.gcd(gcd_ab, c)

print(Sum)

Submission status: Time Limit Exceeded

Solution code:
a = input()
a = int(a)
sum = 0
for i in range(1,a+1):
  for j in range(1,a+1):
    for k in range(1,a+1):
      for b in range(a,0,-1):
        if i%b==0 and j%b==0 and k%b==0:
          sum += b
          break
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

K = int(input())

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

num_list = []
    
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            num = three_gcd(a, b, c)
            num_list.append(num)

print(sum(num_list))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

K=int(input())

S=0
for a in range(1,K+1):
    for b in range(1,K+1):
        calc=np.gcd(a,b)
        for c in range(1,K+1):
            if(c%calc==0):
                S+=calc
            else:
                S+=np.gcd(calc,c)

print(S)

Submission status: Time Limit Exceeded

Solution code:
import math

import math
from functools import reduce

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


a = input()
a = int(a)
count = 0

for l in range(1, a + 1):
    for m in range(1, a + 1):
        for n in range(1, a + 1):
            count +=  gcd(l,m,n)

print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
K = int(input())
memo = np.zeros((K,K),int)
s = 0
for i in range(K):
  for j in range(i,K):
    for k in range(j,K):
      if memo[i][j] != 0:
        if memo[memo[i][j]-1][k] != 0:
          if i == j and j == k:
            s += memo[memo[i][j]-1][k]
          elif i == j or j == k or i == k:
            s += memo[memo[i][j]-1][k] * 3
          else:
            s += memo[memo[i][j]-1][k] * 6
        else:
          memo[memo[i][j]-1][k] = math.gcd(memo[i][j],k+1)
          memo[k][memo[i][j]-1] = memo[memo[i][j]-1][k]
          if i == j and j == k:
            s += memo[memo[i][j]-1][k]
          elif i == j or j == k or i == k:
            s += memo[memo[i][j]-1][k] * 3
          else:
            s += memo[memo[i][j]-1][k] * 6
      else:
        memo[i][j] = math.gcd(i+1,j+1)
        memo[j][i] = memo[i][j]
        if memo[memo[i][j]-1][k] != 0:
          if i == j and j == k:
            s += memo[memo[i][j]-1][k]
          elif i == j or j == k or i == k:
            s += memo[memo[i][j]-1][k] * 3
          else:
            s += memo[memo[i][j]-1][k] * 6
        else:
          memo[memo[i][j]-1][k] = math.gcd(memo[i][j],k+1)
          memo[k][memo[i][j]-1] = memo[memo[i][j]-1][k]
          if i == j and j == k:
            s += memo[memo[i][j]-1][k]
          elif i == j or j == k or i == k:
            s += memo[memo[i][j]-1][k] * 3
          else:
            s += memo[memo[i][j]-1][k] * 6
print(s)

Submission status: Time Limit Exceeded

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


def main():
    n = int(input())
    sum = 0

    for i in range(1,n+1):
        for j in range(i,n+1):
            for k in range(j,n+1):
                a = [i,j,k]
                b = len(list(set(list(itertools.permutations(a,3)))))
                sum = sum + (b*reduce(gcd,a))

    print(sum)

main()

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
nums = []
for i in range(1, a+1):
    nums.append(i)

for balls in itertools.product(nums, repeat=3):
    ans += int(gcd(balls[0], balls[1], balls[2]))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
k = int(input())
total = 0
ab_gcd = []
for a in range(1,k+1):
    for b in range(1,k+1):
        ab_gcd.append(gcd(a,b))
for ab in ab_gcd:
    for c in range(1,k+1):
        abc = gcd(ab,c)
        total += abc
print(total)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

K = int(input())

def sigma(func, frm, to):
    result = 0
    for i in range(frm, to+1):
      for y in range(frm, to+1):
        for z in range(frm, to+1):
          result += func([i, y, z])
    return result

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

if __name__ == "__main__":
  print(sigma(gcd_list, 1, K))

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

d = dict()
k = int(input())
sm = 0

def g(x, y, z):
    t = sorted([x,y,z])
    d.setdefault(str(t), 0)
    if d[str(t)] == 0:
        s = math.gcd(math.gcd(a, b), c)
        d[str(t)] = s
        return s
    else:
        return d[str(t)]

for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            sm += g(a,b,c)

print(sm)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import fractions

K = int(input())

total = 0

for i in range(K):
    for j in range(K):
        for k in range(K):
            gcd1 = fractions.gcd(i+1,j+1)
            total += fractions.gcd(gcd1,k+1)

print(total)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
import itertools


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

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

line = int(input())

a = list(range(1,line + 1))
b = list(range(1,line + 1))
c = list(range(1,line + 1))

result = list(itertools.product(a,b,c))
#print(result)

all = 0

for i in result:
    tmp = gcd(i[0], i[1], i[2])
    all += tmp

print(all)

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())
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:
def gcd(a,b,c):
    #1
    seq  = [a,b,c]
    seq.sort()
    while b > 0:
        r = c%b
        c = b
        b = r
    #2
    seq_2 = [a,c]
    seq_2.sort()
    while a > 0:
        r = c%a
        c = a
        a = r
    return c
    

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

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

print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
K = int(input())
sum_gcd = 0
gcd = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            i = 1
            while i <= min(a,b,c):
                if a % i == 0 and b % i == 0 and c % i == 0:
                   gcd = i  
                i += 1
            sum_gcd += gcd
print(sum_gcd)

Submission status: Time Limit Exceeded

Solution code:
d = {}

def gcd(a,b):
	while a != b:
		if a > b: a -= b
		else: b -= a
	return a

def fastGcd(i,j):
	global d
	g = 1
	if (i,j) in d:
		g = d[(i,j)]
	else:
		g = gcd(i,j)
		d[(i,j)] = g
		d[(j,i)] = g
	return g

		



k = input()
k = int(k)

sum = 0
for i in range(1,k+1):
	for j in range(1, k+1):
		for l in range(1, k+1):
			sum += fastGcd(fastGcd(i,j), l)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math

K = int(input())
nums = [i for i in range(1, K+1)]
product = itertools.product(nums, repeat=3)
ans = 0
for comb in product:
    m = min(comb)
    for i in range(3):
        m = math.gcd(m, comb[i])
    ans += m
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)

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

Submission status: Time Limit Exceeded

Solution code:
import math

X = int(input())
sum = 0


for i in range(1,X+1):
    for j in range(1, X+1):
        for k in range(1, X+1):
            if i==1 or j==1 or k==1:
                sum = sum +1
            else:
                b = math.gcd(i,j)
                a = math.gcd(b,k)
                sum = sum + a
print(sum)

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


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


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

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())


sums = 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)
            y = math.gcd(x,c)
            sums = sums + y

print(sums)

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)
  
data=int(input())
result = [[i+1, j+1, k+1] for i in range(data) for j in range(data) for k in range(data)]

ans=0
#print(result)

for n in result:
  ans+=gcd(n[0],n[1],n[2])
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

K = list(range(1,int(input())+1))
S = 0

for i in itertools.product(K, repeat=3):
    S += gcd(i[0],i[1],i[2])

print (S)

Submission status: Time Limit Exceeded

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

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

if __name__ == "__main__":
    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 += gcd3(a, b, c)
    
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())

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

for i in lis:
    for j in lis:
        for k in lis:
            a.append([i,j,k])
gcd_list = []
for i in a:
    e,f,g = map(int,i)
    e_f = math.gcd(e,f)
    e_g = math.gcd(e,g)
    e_f_g = math.gcd(e_f,e_g)
    gcd_list.append(e_f_g)
print(sum(gcd_list))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
from numba import njit

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


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

print(culc_gcd_of_3(l_p))

Submission status: Time Limit Exceeded

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

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
import itertools
from functools import reduce

def resolve():
    K = int(input())
    sum = 0

    '''
    seq = [num for num in range(1, K+1)]
    print(seq)

    list(itertools.permutations(seq))
    '''
    
    for a in range(1, K+1):
        for b in range(1, K+1):
            for c in range(1, K+1):
                #print("(" + str(a) + ","  + str(b) + "," + str(c) + ") : " + str(gcd(a, b, c)))
                sum += gcd(a, b, c)
    

    print(sum)

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


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

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

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

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

    num = [i for i in range(1,k+1)]
    comb = tuple(itertools.product(num, repeat=3))


    for i in comb:
        ans += gcd(i)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
s = 0
for i in range (1,K + 1):
    for j in range (i + 1,K + 1):
        for k in range (j + 1,K + 1):
            for x in range (66):
                a = min(i,K//3) - x
                if i%a == 0 and j%a == 0 and k%a == 0:
                    s = s + 6 * a
                    break
for i in range(1,K + 1):
    for j in range (i + 1,K + 1):
        for x in range (100):
            a = min(i,K//2) - x
            if i%a == 0 and j%a == 0:
                    s = s + 6 * a
                    break
for i in range(1,K + 1):
    s = s + i

print(s)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
from collections import defaultdict

K = int(input())

myhash = defaultdict(lambda : defaultdict(lambda :defaultdict(int)))

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

def gcd_hash(input_list):
    input_list.sort()

ret = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            arr = [a,b,c]
            arr.sort()
            gcd = myhash[arr[0]][arr[1]][arr[2]]
            if gcd == 0:
                myhash[arr[0]][arr[1]][arr[2]] = gcd_list(arr)
                gcd = myhash[arr[0]][arr[1]][arr[2]]
            ret += gcd

print(ret)

Submission status: Time Limit Exceeded

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

def gcd(l):
    ans = l[0]
    for i in range(1,len(l)):
        ans = fractions.gcd(ans, l[i])
    return ans

ans = 0
for a in range(1,k+1):
    for b in range(a,k+1):
        for c in range(b,k+1):
            l = [a,b,c]
            n = len(set(l))
            if n==2:
                ans += gcd(l)*3
            elif n==3:
                ans += gcd(l)*6
            else:
                ans += gcd(l)

print(ans)

Submission status: Time Limit Exceeded

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

print(sum([gcd(a,b,c) for a in range(1,n+1) for b in range(1,n+1) for c in range(1,n+1)]))

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

def sigma(func, frm, to):
    result = 0
    for i in range(frm, to+1):
        result += func(i)
    #print(result)

def f(x):
    return x

K = int(input())

#print(sigma(f,1,K))

#print(gcd(sigma(f,1,K),sigma(f,1,K),sigma(f,1,K)))

#sigma(sigma(sigma(gcd(), 1, K)))

#print(gcd(sigma(gcd,1,K),sigma(f(K),1,K),sigma(f(K),1,K)))

x = 0

#print()

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            x += gcd(a, b, c)
            """print("a:",end="")
            print(a)
            print("b:",end="")
            print(b)
            print("c:",end="")
            print(c)"""

print(x)

#print(gcd(27,18,9))

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

    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                sorted_nums = sorted([a, b, c])
                sum_n += gcd(gcd(sorted_nums[0], sorted_nums[1]), sorted_nums[2])

    print(sum_n)

q3()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math as mt
from functools import reduce
#N=map(int, input().split())
K=int(input())
count=0
def gcd(*numbers):
    return reduce(mt.gcd, numbers)
for a in range(2,K+1):
    for b in range(2,K+1):
        for c in range(2,K+1):
            count=count+gcd(a,b,c)
print(count+3*K**2-3*K+1)

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
from itertools import product
N = int(input())
List = list(product(list(range(1,N+1)),repeat = 3))
NewList= []
for i in range(len(List)):
    Number = gcd(List[i][0], gcd(List[i][1], List[i][2]))
    NewList.append(Number)
print(sum(NewList))

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)

t = 0
k= int(input(''))+1
for l in range(1,k):
    for m in range(1,k):
        for n in range(1,k):
            if l==m and m==n:
                t+=l
            elif l==m:
                t+=math.gcd(l,n)
            elif l==n:
                t+=math.gcd(l,m)
            elif m==n:
                t+=math.gcd(l,m)
            else:
                t+= gcd_list([l,m,n])
#            print("{}/{}/{} -> {}".format(l,m,n,gcd(l,m,n)))

print(t)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
data_dict = {}
k = int(input())
if k == 1:
    print(1)
else:
    ans = 3 * k * k - 3 * k + 1
    for x in range(2, k + 1):
        for y in range(2, k + 1):
            for z in range(2, k + 1):
                if x == y and y == z:
                    ans += x
                elif x == y:
                    if x < z:
                        a = x
                        b = z
                    else:
                        a = z
                        b = x
                    key = str(a) + "-" + str(b)
                    if key in data_dict:
                        ans += data_dict[key]
                    else:
                        d = gcd(a, b)
                        data_dict[key] = d
                        ans += d
                elif y == z:
                    if y < x:
                        a = y
                        b = x
                    else:
                        a = x
                        b = y
                    key = str(a) + "-" + str(b)
                    if key in data_dict:
                        ans += data_dict[key]
                    else:
                        d = gcd(a, b)
                        data_dict[key] = d
                        ans += d
                elif z == x:
                    if z < y:
                        a = z
                        b = y
                    else:
                        a = y
                        b = z
                    key = str(a) + "-" + str(b)
                    if key in data_dict:
                        ans += data_dict[key]
                    else:
                        d = gcd(a, b)
                        data_dict[key] = d
                        ans += d
                else:
                    if x < y:
                        a = x
                        b = y
                    else:
                        a = y
                        b = x
                    key = str(a) + "-" + str(b)
                    if key in data_dict:
                        c = data_dict[key]
                    else:
                        c = gcd(a, b)
                        data_dict[key] = c
                    if c == 1:
                        ans += 1
                    else:
                        if c < z:
                            key = str(c) + "-" + str(z)
                            if key in data_dict:
                                ans += data_dict[key]
                            else:
                                d = gcd(c, z)
                                data_dict[key] = d
                                ans += d
                        else:
                            key = str(z) + "-" + str(c)
                            if key in data_dict:
                                ans += data_dict[key]
                            else:
                                d = gcd(z, c)
                                data_dict[key] = d
                                ans += d
    print(ans)

Submission status: Time Limit Exceeded

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

ans_list = []

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

print(sum(ans_list))

Submission status: Time Limit Exceeded

Solution code:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
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:
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
K = int(input())
youso = 0

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

print(youso)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 21:45:38 2020

@author: H_Hoshigi
"""

import math

K = 200#int(input())

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