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(a, b):
    if a%b==0: return b
    return gcd(b, a%b)
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(gcd(a,b),c)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
from itertools import product
 
x = int(input())
 
s = 0
for i in product(range(1, x+1), repeat=3):
  s += reduce(math.gcd, i)
print(s)

Submission status: Time Limit Exceeded

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

k = int(input())

ret = 0
for i in range(1,k+1):
	for j in range(1,k+1):
		for l in range(1,k+1):
			g = gcd(i,gcd(j,l))
			#print("i:",i," j:",j," l:",l," gcd:", g)
			ret += g
print(ret)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
ans = 0
k = int(input())
def GCD(a, b):
  if b == 0:
    return a
  else:
    return GCD(b, a%b)
for i in range(1, k+1):
  for j in range(1, k+1):
    gcd = GCD(i, j)
    for l in range(1, k+1):
      ans += GCD(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())
total = 0

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

n = int(input())
total = n**2

for a in range(2, n+1):
    for b in range(1, n+1):
        for c in range(1, n+1):
            total += gcd(a, b, c)
print(total)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())
ans = 0

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b,c):
  bound=min([a,b,c])
  for d in range(bound,0,-1):
    if a%d==b%d==c%d==0:
      return d
def main():
  k=int(input())
  cur=0
  for a in range(1,k+1):
    for b in range(1,k+1):
      for c in range(1,k+1):
        cur+=gcd(a,b,c)
        
  return cur
print(main())

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
import math

from collections import deque 
from functools import reduce
from functools import lru_cache

# input = sys.stdin.readline

n = int(input())

gcd_num = 0

for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            g = math.gcd(i, j)
            gcd_num += math.gcd(g, k)
print(gcd_num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
z=range(int(input()))
y=0
for a in z:
  for b in z:
    for c in z:
      y+=gcd(gcd(a+1,b+1),c+1)
print(y)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
x=int(input())
y=0
for a in range(x):
  for b in range(x):
    for c in range(x):
      y+=gcd(gcd(a+1,b+1),c+1)
print(y)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
k=int(input())
sum_=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            sum_+=reduce(math.gcd,[i,j,l])
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())
sum = 0

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
# import numpy as np

# aとbの最大公約数
def GCD(a,b):
    # ユークリッドの互除法
    if b == 0:
        return a
    else:
        return GCD(b,a % b)



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 = sum + GCD(GCD(i, j),k)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import fractions as ma
n=int(input())
total=0

for a in range(1,n+1):
  for b in range(1,n+1):
    d = ma.gcd(a,b)
    for c in range(1,n+1):
      total += ma.gcd(d,c)
      
print(total)

Submission status: Time Limit Exceeded

Solution code:
def calc_gcd(x, y, z):
    rem = x % y

    while rem != 0:
        x = y
        y = rem
        rem = x % y

    rem = y % z

    while rem != 0:
        y = z
        z = rem
        rem = y % z

    return z


k = int(input())
gcdSum = 0

numRangeList = range(1, k + 1)

for a in numRangeList:
    for b in numRangeList:
        for c in numRangeList:
            singleGcd = calc_gcd(a, b, c)
            gcdSum += singleGcd

print(gcdSum)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

K = int(input())

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

print(res)

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)

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

Submission status: Time Limit Exceeded

Solution code:
import math


num = int(input())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1,n+1):
    for j in range(i, n+1):
        for k in range(j, n+1):
            if i == j and j == k:
                ans += i
            
            elif len({i,j,k}) == 2:
                ans += fractions.gcd(fractions.gcd(i,j),k)*3
            
            elif len({i,j,k}) == 3:
                ans += fractions.gcd(fractions.gcd(i,j),k)*6
        
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def cul_gcd_of_2numbers(a, b):
  large = max(a, b)
  small = min(a, b)
  while 1:
      surplus = large%small
      if surplus == 0:
          return (small)
      else:
          large = small
          small = surplus
     
    
    

if __name__ == "__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):
        before = cul_gcd_of_2numbers(a,b)
        result = cul_gcd_of_2numbers(before,c)
        sum = sum + result
    
  print(sum)

Submission status: Time Limit Exceeded

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

def sum_of_gcd(k):
  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))
  return ans

n = int(input())
print(sum_of_gcd(n))

Submission status: Time Limit Exceeded

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

def sum_of_gcd(k):
  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))
  return ans

n = int(input())
print(sum_of_gcd(n))

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())
c=0

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import itertools
#from math import gcd
def gcd(a,b):
    x=max(a,b)
    y=min(a,b)
    if x%y==0:return y
    else:
        while(x%y!=0):
            z=x%y
            x=y
            y=z
        return z

# K = list(map(int, (stdin.readline().strip().split())))[0]
# i=[x for x in range(1,K+1)]
# j=[x for x in range(1,K+1)]
# k=[x for x in range(1,K+1)]
# num_list=set(map(tuple,(sorted(x) for x in (itertools.product(i,j,k)))))
#
# ans=0
# for i,j,k in num_list:
#     if i==j:
#         if j==k:
#             ans+=K
#         else:
#             ans+=gcd(i,gcd(j,k))*3
#     elif j==k:ans+=gcd(i,gcd(j,k))*3
#     else:ans+=gcd(i,gcd(j,k))*6
K = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import numpy as np

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+=np.gcd(i,np.gcd(j,k))
print(str(ans)+"\n")

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

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

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,gcd(j,k))
print(str(ans)+"\n")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
sum = 0

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


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

print(str(sum))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

print(total)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
memo = {}

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

print(total)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from math import gcd

log = {}
K = int(input())
sum_gcd = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            key = str(sorted([a, b, c]))
            if key in log:
                sum_gcd += log[key]
            else:
                result = gcd(gcd(a, b), c)
                sum_gcd += result
                log[key] = result
print(sum_gcd)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from math import gcd

def gcd_m(*args):
    return reduce(gcd, args)

log = {}
K = int(input())
sum_gcd = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            key = str(sorted([a, b, c]))
            if key in log:
                sum_gcd += log[key]
            else:
                result = gcd_m(a, b, c)
                sum_gcd += result
                log[key] = result
print(sum_gcd)

Submission status: Time Limit Exceeded

Solution code:
import math
 
k = int(input())
 
def tgcd(a,b,c):
  f = math.gcd(a,b)
  g = math.gcd(f,c)
  return g
s = 0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      p = tgcd(a,b,c)
      s += p
print(s)

Submission status: Time Limit Exceeded

Solution code:
import math
 
k = int(input())
 
def tgcd(a,b,c):
  f = math.gcd(a,b)
  g = math.gcd(f,c)
  return g
l = []
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      p = tgcd(a,b,c)
      l.append(p)
print(sum(l))

Submission status: Time Limit Exceeded

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

def gcd_m(*args):
    a, b = args[0], args[1]
    for i in range(2, len(args)):
        a, b = gcd(a, b), args[i]

    return gcd(a, b)

log = {}
K = int(input())
sum_gcd = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            key = str(sorted([a, b, c]))
            if key in log:
                sum_gcd += log[key]
            else:
                result = gcd_m(a, b, c)
                sum_gcd += result
                log[key] = result
print(sum_gcd)

Submission status: Time Limit Exceeded

Solution code:
import fractions

k = int(input())

def tgcd(a,b,c):
  f = fractions.gcd(a,b)
  g = fractions.gcd(f,c)
  return g
l = []
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      p = tgcd(a,b,c)
      l.append(p)
print(sum(l))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
def gcd(a,b):
    x=max(a,b)
    y=min(a,b)
    if x%y==0:return y
    else:
        while(x%y!=0):
            z=x%y
            x=y
            y=z
        return z

K = list(map(int, (stdin.readline().strip().split())))[0]
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:
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a%b != 0:
        a, b = b, a%b
    return b

def gcd_m(*args):
    a, b = args[0], args[1]
    for i in range(2, len(args)):
        a, b = gcd(a, b), args[i]

    return gcd(a, b)

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

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
tmp = 0
sum = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            tmp = math.gcd(i,j)
            sum = sum + math.gcd(tmp,k)
            
print(sum)

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:
import numpy as np

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 += np.gcd.reduce([i,j,k])
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
from functools import reduce

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

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

N = int(input())
a = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            a = a + int(reduce(math.gcd,{i,j,k}))
print(a)

Submission status: Time Limit Exceeded

Solution code:
import math

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import fractions
s = 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):
            s += fractions.gcd(fractions.gcd(i, j), k)
print(s)

Submission status: Time Limit Exceeded

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


s = 0

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

#s = s*6 + t*3 + int(n*(n+1)*0.5)
print(s)

Submission status: Time Limit Exceeded

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


s = 0
n = int(input())


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
gcd = lambda a,b : a if b == 0 else gcd(b, a % b)
r = range(1,K+1)
print(sum(gcd(gcd(a,b),c)for a in r for b in r for c in r))

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
K=int(input())
Kl=range(1,K+1)
L=list(itertools.product(Kl,Kl,Kl))
 
counter=0
for l in L:
  l=list(l)
  ans = l[0]
  for i in range(1,3):
    ans=math.gcd(ans, l[i])
  counter+=ans
print(counter)

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
counter=0
for i in range(1,a+1):
    for j in range(i,a+1):
        for k in range(j,a+1):
            if i==j and j==k:
                times=1
            elif i!=j and j!=k and k!=i:
                times=6 
            else:
                times=3
            
            for l in range(i,0,-1): 
                if i%l==0 and j%l==0 and k%l==0:
                    counter+=(l*times)
                    break
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
 
 
def gcd(a, b):
    if a > b:
        a, b = b, a
    while a != 0:
        a, b = b % a, a
    return b
 
 
ans = 0
for p in range(1, k + 1):
    for q in range(1, k + 1):
        for r in range(1, k + 1):
            ans += gcd(gcd(p, q), r)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

# 2つ同じ
total += 6*(K-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)
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 numpy as np
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 += np.gcd(i, np.gcd(j, k))            
print(ans)

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 l in range(1,K+1):
            sum += math.gcd(math.gcd(i,j),l)

print(sum)

Submission status: Time Limit Exceeded

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

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

print(sum)

Submission status: Time Limit Exceeded

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

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

K = int(input())

if K == 1:
    ans = 1
elif K == 2:
    ans = 9
else:
    ans = 0
    for i in range(1, K+1):
        ans += i
        for j in range(i+1, K+1):
            ans += gcd(i, j) * 6
            for k in range(j+1, K+1):
                ans += gcd(i, j, k) * 6

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
sum = 0
class gcd:
    def __init__(self,a,b,c):
        self.a=a
        self.b=b
        self.c=c
        
    def gcds(self):
        if self.a>self.b:
            x=self.a
            y=self.b
        else:
            x=self.b
            y=self.a
            
        while x % y!=0:
            tem_y = y
            y = x % y 
            x = tem_y
       
        gcd_1 = y
        
        if gcd_1>self.c:
            x=gcd_1
            y=self.c
        else:
            x=self.c
            y=gcd_1
            
        while x % y!=0:
            tem_y = y
            y = x % y 
            x = tem_y
       
        return int(y)

for i in range(K):
    for j in range(K):
        for l in range(K):
            sum = sum + gcd(i+1,j+1,l+1).gcds()
            
print(sum)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
import fractions
x=0
c=0
d=0
for i in range(1,k+1):
  for j in range(i,k+1):
    for k in range(j,k+1):
      d=fractions.gcd(i,j)
      c=fractions.gcd(d,k)
      if i!=j and j!=k:
        x+=6*c
      elif i==j==k:
        x+=c
      else:
        x+=3*c
print(x)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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


K = int(input())
ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
import math
k=int(input())
total=0
info=[0]
for i in range(1,201):
    for j in range(1,201):
        if j<i:
            info.append(0)
            continue
        info.append(math.gcd(i,j))
        #print(str(i)+" "+str(j)+" "+str(math.gcd(i,j)))
#print(info[202])
#print(info)
for i in range(1,k+1):
    a=[]
    a.append(i)
    for j in range(1,k+1):
        a.append(j)
        for m in range(1,k+1):
            a.append(m)
            a=sorted(a)
            gcd=info[(a[0]-1)*200+a[1]]
            b=min(gcd,a[2])
            c=max(gcd,a[2])
            gcd=info[(b-1)*200+c]
            total+=gcd
            #print(gcd)
            #print(a)
            a=[i,j]
        a=[i]
print(total)

Submission status: Time Limit Exceeded

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

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:
import math
K = int(input())
S = 0
for a in range(K):
    for b in range(K):
        for c in range(K):
            S += math.gcd(math.gcd(a+1,b+1),c+1)
print(S)

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 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:
import math
from functools import reduce
from math import gcd
K = int(input())
A=[]
B=[]
sum = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        A.append(gcd(a,b))
for x in range(len(A)):
    for c in range(1,K+1):
        B.append(gcd(A[x],c))
for i in range(len(B)):
    sum +=B[i]
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K = int(input())

a = 1
b = 1
c = 1
d = 0

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
sum =0
count = 0

def euclidean(p, q):
     if p % q == 0:
          return q
     else:
          return euclidean(q, p % q)

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

Submission status: Time Limit Exceeded

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

c = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for l in range(1,K+1):
            a = math.gcd(math.gcd(i,j), l)
            c += a

print(c)

Submission status: Time Limit Exceeded

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

k = int(input())
val = [[0]*(k+1) for i in range(k+1)]
sum = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        if(val[i][j] == 0):
            val[i][j] = gcd(i,j)
        for l in range(1,k+1):
            if(val[val[i][j]][l] == 0):
                val[val[i][j]][l] = gcd(val[i][j],l)
            sum = sum + val[val[i][j]][l]

print(sum)

Submission status: Time Limit Exceeded

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

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

print(c)

Submission status: Time Limit Exceeded

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

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

print(sum)

Submission status: Time Limit Exceeded

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

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b):
    if(a%b==0):
        return b
    else:
        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 = sum + gcd(gcd(i,j),k)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
import collections

k = int(input())
gcd_table = [[0] * k for i in range(k)]
for i in range(1, k+1):
    for j in range(i, k+1):
        gcd_table[i-1][j-1] = math.gcd(i, j)

ans = 0
combination_list = [0, 1, 3, 6]
for p in range(1, k+1):
    for q in range(p, k+1):
        if gcd_table[p-1][q-1] == 0:
            tmp_gcd = math.gcd(p, q)
            gcd_table[p-1][q-1] = tmp_gcd
        else:
            tmp_gcd = gcd_table[p-1][q-1]
        for r in range(q, k+1):
            if gcd_table[q-1][r-1] == 0:
                tmp_gcd_2 = math.gcd(q, r)
                gcd_table[q-1][r-1] = tmp_gcd_2
            else:
                tmp_gcd_2 = gcd_table[q-1][r-1]
            unique_num = len(collections.Counter([p, q, r]))
            ans += math.gcd(tmp_gcd, tmp_gcd_2) * combination_list[unique_num]
print(ans)