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:
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


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

ans = 0

for i in range(1, k + 1):
    for j in range(1, k + 1):
        res.append(gcd(i, j))
        
for n in range(1, k + 1):
    for r in list(res):
        ans += gcd(int(r), n)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


k = int(input())

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


k = int(input())

ans = 0

for i in range(k + 1):
    for j in range(k + 1):
        for n in range(k + 1):
            if i == 0 or j == 0 or n == 0:
                continue
            ans += gcd(gcd(i, j), n)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

k=int(input())

ans=0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(S)

Submission status: Time Limit Exceeded

Solution code:
import math

k=int(input())

sum=0
for l in range(k):
    for m in range(k):
        for n in range(k):
            tmp=l+1
            tmp=math.gcd(tmp,m+1)
            tmp=math.gcd(tmp,n+1)
            sum+=tmp

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
  
k=int(input())
r=0
for i in range(k):
  for j in range(k):
    for l in range(k):
      r+=gcd(i+1,j+1,l+1)
print(r)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce


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

n=int(input())
l1=range(1,n+1)
l2=range(1,n+1)
l3=range(1,n+1)

count=0

for i in l1:
    for j in l2:
        for k in l3:
            count+=gcd_list([i,j,k])

print(count)

Submission status: Time Limit Exceeded

Solution code:
def gcd(p, q):
    while (q != 0):
        r = p % q
        p = q
        q = r
    return p


def sum_of_gcd_tuples():
    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 += gcd(gcd(a, b), c)

    print(total)


sum_of_gcd_tuples()

Submission status: Time Limit Exceeded

Solution code:
# P3:
def get_gcd(numbers):
    """Helper function to get GCD of list of numbers."""
    import math
    from functools import reduce

    # gcd is associative
    return reduce(lambda x, y: math.gcd(x, y), numbers)


def sum_of_gcd_tuples():
    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):
                if a == b and b == c:
                    total += a
                    continue
                if a == 1 or b == 1 or c == 1:
                    total += 1
                    continue
                else:
                    total += get_gcd([a, b, c])

    print(total)


sum_of_gcd_tuples()

Submission status: Time Limit Exceeded

Solution code:
# P3:
def get_gcd(numbers):
    """Helper function to get GCD of list of numbers."""
    import math
    from functools import reduce

    if 1 in numbers:
        return 1

    # gcd is associative
    return reduce(lambda x, y: math.gcd(x, y), numbers)


def sum_of_gcd_tuples():
    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 += get_gcd([a, b, c])

    print(total)


sum_of_gcd_tuples()

Submission status: Time Limit Exceeded

Solution code:
def get_gcd(numbers):
    """Helper function to get GCD of list of numbers."""
    import math
    from functools import reduce
    # gcd is associative
    return reduce(lambda x, y: math.gcd(x, y), numbers)


def sum_of_gcd_tuples():
    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 += get_gcd([a, b, c])

    print(total)


sum_of_gcd_tuples()

Submission status: Time Limit Exceeded

Solution code:
import math

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

K = int(input())

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

print(A)

Submission status: Time Limit Exceeded

Solution code:
import math as mt
import itertools as iters

K = int(input())
A = 0
for a,b,c in iters.product(range(1,K+1),repeat=3):
    A += mt.gcd(a,mt.gcd(b,c))
print(A)

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

k = int(input())
sum_gcd = 0

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

for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            d = gcd(a, b, c)
            sum_gcd += d
print(sum_gcd)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
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(gcd(a, b), c)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
line = input()
sum_ =0
import math
sto =0

for i in range(int(line)):
  for s in range(int(line)):
    for t in range(int(line)):
      sto =math.gcd(s+1,t+1)
      sum_ +=math.gcd(i+1,sto)
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)

def main(x):
    digit = []
    for i in range(int(x)):
        iter_digit = i + 1
        digit.append(iter_digit)

    combination_list = list(itertools.product(digit, repeat=3))

    final_result = 0
    for com_list in combination_list:
        com_list = list(com_list)
        result = gcd(com_list)
        final_result += result

    print(final_result)


if __name__ == '__main__':
    x = input()
    main(x)

Submission status: Time Limit Exceeded

Solution code:
import math  
from functools import reduce

n = int(input())
count = 0

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

for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            m = gcd(i,j,k)
            count += m
print(count)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
import math
p=0
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,math.gcd(j,k))
print(p)

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

num = int(input())
sum = 0

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

for a in range(1, num + 1):
  for b in range(1, num + 1):
    for c in range(1, num + 1):
      sum += gcd(a, b, c)

print(sum)

Submission status: Time Limit Exceeded

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

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:
import numpy as np
k = int(input())

ans = 0
for a in range(1,k+1):
  for b in range(1,k+1):
    tmp = np.gcd(a,b)
    for c in range(1,k+1):
      ans += np.gcd(tmp,c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
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 += np.gcd(np.gcd(a,b),c)

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
#n = 200
s = 0
index = []

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

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


print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

	ans = 0
	l = list(itertools.product(list(range(1,s+1)),repeat = 3))

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

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce


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

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

Submission status: Time Limit Exceeded

Solution code:
import math
k = int(input())
a = 0
for m in range(1,k+1):
    for n in range(1,k+1):
        for l in range(1,k+1):
             b = math.gcd(m,n)
             #print("b={}".format(b))
             a = a + math.gcd(b,l)
             #print("a={}".format(a))
print(a)

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc162/tasks/abc162_c
# -*- coding: utf-8 -*-
import math
ans = 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):
      ans += math.gcd(math.gcd(i,j),k)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
a=0
b=0
for i in range(1,K+1):
  for j in range(1,i+1):
    for k in range(1,j+1):
      for l in range(1,K+1):
       
        if i%l==0 and j%l==0 and k%l==0:
          a=l
        if l==k:
          b=b+3*a
          
          if i==j and j==k and k==i:
         
            b=b-2*a
          if i!=j and j!=k and k!=i:
            b=b+3*a
          break
print(b)

Submission status: Time Limit Exceeded

Solution code:
def f(x,y):
    if x%y==0:
        return y
    x,y=y,x%y
    return f(x,y)

def main():
    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+=f(a,f(b,c))
    return sum

print(main())

Submission status: Time Limit Exceeded

Solution code:
def gcd(p,q):
    while(q!=0):
        r=p%q
        p=q
        q=r
    return p
    
n=int(input())
sum=0
for a in range(1,n+1):
    for b in range(1,n+1):
        for c in range(1,n+1):
            sum+=gcd(a,gcd(b,c))
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
K = int(input())
S = 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, c)
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):
      ans += math.gcd(math.gcd(a,b),c)

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
class Gcd:

    def __init__(self, K):
        self.table = [[None] * K for i in range(K)]
        return

    def gcd(self, x, y):
        if self.table[x - 1][y - 1] is not None:
            return self.table[x - 1][y - 1]

        if x == y:
            self.table[x - 1][y - 1] = x
            return x
        elif x > y:
            z = x % y
            if z == 0:
                self.table[x - 1][y - 1] = y
                return y
            else:
                z = self.gcd(z, y)
                self.table[x - 1][y - 1] = z
                return z
        else:
            return self.gcd(y, x)

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

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

if __name__ == '__main__':
    quest_c()

Submission status: Time Limit Exceeded

Solution code:
import math

k = int( input() )
out_sum = 0

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

print( out_sum )

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def main():
    K = int(input())
    s = 0
    for i in range(1, K+1):
        for j in range(1, K+1):
            for k in range(1, K+1):
                s += gcd(i, j, k)
    print(s)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
import itertools

x = input()

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

digit = []
for i in range(int(x)):
    iter_digit = i + 1
    digit.append(iter_digit)

combination_list = list(itertools.product(digit, repeat=3))

final_result = 0
for com_list in combination_list:
    com_list = list(com_list)
    result = gcd(com_list)
    final_result += result

print(final_result)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

# 2つ同じ
#for i in range(0,K-1):
#  total += 6*(K-1-i)*(i+1)

total += 6*(K-1)	# １つが必ず1の場合

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

# バラバラ
total += int(6*(K-1)*(K-2)/2)	# １つが必ず1の場合
for i in range(1,K-2):
  for j in range(i+1,K-1):
    for k in range(j+1,K):
      if (j+1)%(i+1) == 0 and (k+1)%(i+1) == 0:
        total += (i+1)*6
      else:
        tmp = 0
        for l in range(1,i+1):
          if (i+1)%l == 0 and (j+1)%l == 0 and (k+1)%l == 0:
            tmp = l
        total += tmp*6
print(total)

Submission status: Time Limit Exceeded

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

x = input()

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

digit = []
for i in range(int(x)):
    iter_digit = i + 1
    digit.append(iter_digit)

combination_list = list(itertools.product(digit, repeat=3))

final_result = 0
for com_list in combination_list:
    com_list = list(com_list)
    result = gcd(com_list)
    final_result += result

print(final_result)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

class abc_162:
    
    def __init__(self):
        pass
        
    def C(self):
        K=int(input())
        sum_gcd=0
        
        for i in range(1,K+1):
            for j in range(1,K+1):
                for k in range(1,K+1):
                    sum_gcd+=self.gcd(i,j,k)
        
        print(sum_gcd) 


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


if __name__=='__main__':
    obj=abc_162()
    obj.C()

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

n = int(input())

answer = 0.0

for i in range(1,n+1):
  
  for j in range(1,n+1):
    
    for h in range(1,n+1):
      f = gcd(i,j,h)
      answer += f
      
print(int(answer))

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

n = int(input())

answer = 0

for i in range(1,n+1):
  
  for j in range(1,n+1):
    
    for h in range(1,n+1):
      f = gcd(i,j,h)
      answer += f
      
print(answer)

Submission status: Time Limit Exceeded

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

n = int(input())
s = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        a = gcd(i,j)
        for k in range(1,n+1):
            b = gcd(a,k)
            s += b
print(s)

Submission status: Time Limit Exceeded

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

n = int(input())
s = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            a = gcd(i+1,j+1)
            b = gcd(a,k+1)
            s += b
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):
            ans += math.gcd(a, math.gcd(b, c))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache

K = int(input())
sum = 0

@lru_cache()
def gcd(x,y):
  r = x % y
  while r> 0:
    x = y
    y = r
    r = x%y
  return y
  
for a in range(K):
  for b in range(K):
    for c in range(K):
      sum += gcd(gcd(a+1,b+1),c+1)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

import time
import numpy as np
import math


############################################

# read data for n sequences.
temp = stdin.readline().split()
N = int(temp[0])+1

out = 0
for i in range(1,N):
    for j in range(1,N):
        for k in range(1,N):
            part = math.gcd(j,k)
            out += math.gcd(part,i)
print(out)

Submission status: Time Limit Exceeded

Solution code:
import math
def gcd_arg3(a,b,c):
    return math.gcd(a,math.gcd(b,c))

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 += gcd_arg3(a,b,c)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
def gcd_arg3(a,b,c):
    return math.gcd(a,math.gcd(b,c))

k = int(input())

ans_list = list()
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans_list.append(gcd_arg3(a,b,c))

print(sum(ans_list))

Submission status: Time Limit Exceeded

Solution code:
k = int(input())


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

def gcd_arg3(a,b,c):
    return gcd_arg2(c,gcd_arg2(a,b))

ans_list = list()
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans_list.append(gcd_arg3(a,b,c))

print(sum(ans_list))

Submission status: Time Limit Exceeded

Solution code:
def GCD(x,y):
  if y == 0:
    return x
  return GCD(y,x % y)

def sgcd(K):
  rt = 0
  for a in range(1,K+1):
    for b in range(1,K+1):
      buf = GCD(a,b)
      for c in range(1,K+1):
        rt += GCD(buf,c)
  return rt
K = int(input())
print(sgcd(K))

Submission status: Time Limit Exceeded

Solution code:
def GCD(x,y):
  if y == 0:
    return x
  return GCD(y,x % y)

def sgcd(K):
  rt = 0
  for a in range(1,K+1):
    for b in range(1,K+1):
      for c in range(1,K+1):
        rt += GCD(GCD(a,b),c)
  return rt
K = int(input())
print(sgcd(K))

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

Submission status: Time Limit Exceeded

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

# ans = 0
# for a in range(1, K+1):
#   for b in range(1, K+1):
#     for c in range(1, K+1):
#       ans += fractions.gcd(a, fractions.gcd(b,c))
# print(ans)

tmp = [0] * 40000
ans = 0
k = 0
for i in range(1, K+1):
  for j in range(1, K+1):
    tmp[k] = fractions.gcd(i, j)
    k += 1

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

# reduce(function, iterable, initializer)
def gcd(*number):
    return reduce(math.gcd, number)

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

sum = 0
K = int(input())
for i in range(1,K+1):
    for j in range(1,K+1):
        tmp = gcd(i, j)
        for k in range(1,K+1):
            sum += gcd(tmp, k)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())


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


ans = 0
for x in range(1, K + 1, 1):
    for y in range(1, K + 1, 1):
        ans = ans + sum(list(map(lambda z: gcd3(x, y, z), range(1, K+1, 1))))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())


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


ans = 0
for x in range(1, K + 1, 1):
    for y in range(1, K + 1, 1):
        tmp = list(map(lambda z: gcd3(x, y, z), range(1, K+1, 1)))
        ans = ans + sum(tmp)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())


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


ans = 0
for x in range(1, K + 1, 1):
    for y in range(1, K + 1, 1):
        for z in range(1, K + 1, 1):
            ans = ans + gcd3(x, y, z)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

# reduce(function, iterable, initializer)
def gcd(*number):
    return reduce(math.gcd, number)

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

K = int (input())
sum = 0

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

print (sum)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
import math

K = int (input())
sum = 0
for a, b, c in product(range(1,K+1), repeat=3):
    sum += math.gcd(math.gcd(b,c),a)
print (sum)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
sum = 0
def gcd(x,y):
  r = x % y
  while r> 0:
    x = y
    y = r
    r = x%y
  return y
  
for a in range(K):
  for b in range(K):
    for c in range(K):
      sum += gcd(gcd(a+1,b+1),c+1)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools

K=int(input())
s=0
for a,b,c in itertools.product(range(1,K+1),range(1,K+1),range(1,K+1)):
    	s+=math.gcd(math.gcd(a,b),c)
print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def find_gcd(x, y): 
    while(y): 
        x, y = y, x % y 
  
    return x 
K = int (input())
sum = 0

for i in range (1, K+1):
    for j in range (1, K+1):
        for k in range (1, K+1):
            sum += find_gcd(i, find_gcd(j,k))

print (sum)

Submission status: Time Limit Exceeded

Solution code:
import math

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
from math import gcd

K = int(input())
print(sum([gcd(a,gcd(b,c)) for a,b,c in [i for i in product(range(1, K+1), repeat=3)]]))

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

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

dp = np.zeros((N+1, N+1))
ans = np.zeros((N+1, N+1, N+1))

def gcd(a, b):
    if a < b:
        a, b = b, a
    
    if dp[a][b] != 0:
        return dp[a][b]

    while b>0:
        a, b = b, a % b
    
    dp[a][b] = a
    return a

for i in range(1,N+1):
    for j in range(1,N+1):
        temp = gcd(i, j)
        for k in range(1,N+1):
            ans[i][j][k] = gcd(temp, k)
            
print(int(ans.sum()))

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
n = range(1,int(input())+1)
pp = list(itertools.product(n, repeat=3))
sum = 0
for p in pp:
  sum+=math.gcd(math.gcd(p[0],p[1]),p[2])
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
import itertools
n = np.arange(1,int(input())+1)
pp = list(itertools.product(n, repeat=3))
sum = 0
for p in pp:
  sum+=math.gcd(math.gcd(p[0],p[1]),p[2])
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
import itertools
nums = np.arange(1,int(input())+1)
pp = list(itertools.product(nums, repeat=3))
sum = 0
for p in pp:
  k=math.gcd(p[0],p[1])
  sum+=math.gcd(k,p[2])
print(sum)

Submission status: Time Limit Exceeded

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

k=int(input())
s=0
for a in range(1, k+1):
  for b in range(1, k+1):
    for c in range(1, k+1):
      s+=gcd_(gcd_(b, c), a)
print(s)

Submission status: Time Limit Exceeded

Solution code:
K=input()
K=int(K)
import fractions
def gcd(a,b,c):
  return fractions.gcd(fractions.gcd(a,b),c)
m=0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      m=m+gcd(i,j,k)
print(m)

Submission status: Time Limit Exceeded

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

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):
    z = gcd2(a, b)
    return(gcd2(c, z))

k = int(input())
t = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            t += gcd3(a, b, c)
print(t)

Submission status: Time Limit Exceeded

Solution code:
import fractions

K = int(input())

ans = 0
a=[]
for i in range(1,K+1):
	for j in range(1, K+1):
		tmp = fractions.gcd(i,j)
		for k in range(1, K+1):
			ans+=fractions.gcd(tmp,k)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

sum = 0

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


for a in range(1, k + 1):
    for b in range(1, k + 1):
        ab_gcd = gcd(a, b)
        for c in range(1, k + 1):
            abc_gcd = gcd(c, ab_gcd)
            sum += abc_gcd
        
print(sum)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

def gcd(x,y):
    while y:
        x ,y = y ,x%y
    return x



total = 0

for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            total += gcd(a , gcd(b,c))

print(total)

Submission status: Time Limit Exceeded

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

def gcd(m, n):
    x = max(m, n)
    y = min(m,n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z

K = int(input())
ans = 0

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