Problem:


Score : 300 points

Problem Statement

Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

Constraints

1 \leq K \leq 200

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print the value of \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Sample Input 1

2

Sample Output 1

9

\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)
+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)
=1+1+1+1+1+1+1+2=9

Thus, the answer is 9.

Sample Input 2

200

Sample Output 2

10813692



Sample input:
2


Sample output:
9

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce


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


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


n = int(input())

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

print(result)

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
from math import gcd

samu = 0

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


print(str(int(samu)))

Submission status: Time Limit Exceeded

Solution code:
def gcd(p,q):
  if p%q==0:
    return q
  else:
    return gcd(q,p%q)
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):
      d=gcd(a,b)
      s+=gcd(d,c)
print(s)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
sum_ = 0

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

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

K = int(input())
count = 0
for abc in list(itertools.product(list(range(1, K+1)), repeat=3)):
    count += reduce(math.gcd, abc)

print(count)

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

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

print(count)

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):
    if i == 1:
        sum_ += k ** 2
    else:
        for j in range(1, k+1):
            if j == 1:
                sum_ += k
            else:
                for l in range(1, k+1):
                    if l == 1:
                        sum_ += 1
                    else:
                        sum_ += reduce(math.gcd, [i, j, l])
            
print(sum_)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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_list([i, j, l])
            
print(sum_)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

K = int(input())

total = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            total = total + np.gcd.reduce([i, j, k])

print(total)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

k = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
k = int(input())+1
ans = 0
for i in range(1,k):
  for j in range(1,k):
    for l in range(1,k):
      if 1 in [i,j,k]:
          ans+=1
      else:
          ans += gcd(gcd(i,j),l)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

k = int(input())

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

print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

def gcd(a,b,c):
    gc =1
    for i in range(1,min(a,b,c)+1):
        if a%i==0 and b%i==0 and c%i ==0:
            gc=i
    return gc

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
mem={}
def gcd(a,b,c):
    key=tuple(sorted((a,b,c)))
    if key in mem:
        return mem[key]
    ret=1
    for i in range(2, min(a,b,c)+1):
        if a%i==0 and b%i==0 and c%i==0:
            ret=i
    mem[key]=ret
    return ret
        
ans=0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            ans+=gcd(i, j, k)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#ans = [0]*n
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):
            num = math.gcd(i, j)
            ans += math.gcd(num, l)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools,math
K = int(input())
c = [i for i in range(1,K+1)]

g = itertools.product(c,repeat=3) #リストの中のすべての並ばせ方

ans = 0
for i,j,k in g:
  ans += math.gcd( math.gcd(i,j) , k )

print(ans)

Submission status: Time Limit Exceeded

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

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

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

print(ans)

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

      
print(sum)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
def calcgcd(a, b):
  if a > b:
    a, b = b, a
  while a > 0:
    a, b = b%a, a
  return b
r = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    ab = calcgcd(a, b)
    for c in range(1, K+1):
      g = calcgcd(ab, c)
      r += g
print(r)

Submission status: Time Limit Exceeded

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


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


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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())


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


ans = 0
for 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:
from math import gcd

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())


def gcd(a, b, c):
    mi = min(a, b, c)
    for k in range(mi, 0, -1):
        if a % k == 0 and b % k == 0 and c % k == 0:
            return k


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

print(ans)

Submission status: Time Limit Exceeded

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


def gcd(a, b, c):
    mi = min(a, b, c)
    for k in range(mi, 0, -1):
        if a % k == 0 and b % k == 0 and c % k == 0:
            return k


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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

Submission status: Time Limit Exceeded

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


def gcd(a, b, c):
    for k in range(K, 0, -1):
        if a % k == 0 and b % k == 0 and c % k == 0:
            return k


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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


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


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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
from math import gcd

k = int(input())
nums = range(1,k+1)
##numsから重複を許して、3つを取り並べる(重複順列)
list = list(product(nums,repeat=3))

answer = []
##gcd(a,b,c) a,bの最大公約数を計算した後、その最大公約数とcの最大公約数を計算
for i in range(len(list)):
    answer.append(gcd(gcd(list[i][0],list[i][1]),list[i][2]))
print(sum(answer))

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
import math
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 = []
for a in range(1, K+1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            gcd = reduce(math.gcd, [a, b, c])
            Sum.append(gcd)

print(sum(Sum))

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K = int(input())

Sum = []
for a in range(1, K+1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            gcd = gcd_list([a, b, c])
            Sum.append(gcd)

print(sum(Sum))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
def gcd(_a, _b):
	if _b==0:return _a
	return gcd(_b, _a%_b)

def lcm(_a, _b):
	return _a * _b // gcd(_a, _b)

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

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
import math
from functools import reduce
G = []
for a in range(K):
    for b in range(K):
        for c in range(K):
            g = reduce(math.gcd,[a+1,b+1,c+1])
            G.append(g)
print(sum(G))

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

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

print(sum)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

        sum = 0

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

        print("{}".format(sum))

if __name__=="__main__":
        main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
K = int(input())

def gcd(a,b,c):
  return np.gcd(a,np.gcd(b,c))

sum = 0

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

Submission status: Time Limit Exceeded

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

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
K = int(input())
answer = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            answer += gcd(gcd(i,j),k)

print(answer)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

def gcd(n):
  m = set()
  for i in range(1, n+1):
    if(n%i == 0):
      m = m | {i}
  return m

m = []
for i in range(1, K+1):
  m.append(gcd(i))
sum = 0
for i in range(1, K+1):
  for j in range(1, K+1):
    m_max2 = m[i-1] & m[j-1]
    for k in range(1, K+1):
      sum += max(m_max2 & m[k-1])
print(sum)

Submission status: Time Limit Exceeded

Solution code:
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):
      m = max([i, j, k])
      for h in range(m, 0, -1):
        if(i%h==0 and j%h==0 and k%h==0):
          sum += h
          break
print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
ans=0
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x

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)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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


d = {}
def gcd(a,b,c):
    st = tuple(sorted((a,b,c)))
    if st not in d:
        res = math.gcd(a, math.gcd(b,c))
        d[st] = res
    return d[st]

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

v = int(input())
sum = 0

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math

v = int(input())
sum = 0

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math

v = int(input())
sum = 0

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a, b, c):
    r = 1
    if a == 1 or b == 1 or c == 1:
        return 1
    for i in range(min(a, b, c) + 1):
        i += 1
        if a % i == 0 and b % i == 0 and c % i == 0:
            r = i
    return r

v = int(input())
sum = 0

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a, b, c):
    r = 1
    for i in range(min(a, b, c) + 1):
        i += 1
        if a % i == 0 and b % i == 0 and c % i == 0:
            r = i
    return r

v = int(input())
sum = 0

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
#C
def gcd(a, b):
    if b > a:
        a, b = b, a
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
        
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):
            tmp = gcd(a, b)
            ans += gcd(tmp, c)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
tmp = input().split()
K = int(tmp[0])

SGCD = 0

def gcd(a,b,c):
    for ga in range(a+1)[1:]:
        if a % ga == 0:
            Ga = a/ga
            if b % Ga == 0 and c % Ga == 0:
                return Ga
        
        if ga > a/2:
            return 1

for c in range(K+1)[1:]:
    for b in range(c+1)[1:]:
        for a in range(b+1)[1:]:
            if not a == b and not b == c:
                SGCD = SGCD + 6*gcd(a,b,c)
            elif a == b and not b == c:
                SGCD = SGCD + 3*gcd(a,b,c)
            elif not a == b and b == c:
                SGCD = SGCD + 3*gcd(a,b,c)
            elif a == b and b == c:
                SGCD = SGCD + gcd(a,b,c)

print(int(SGCD))

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
from math import gcd
k = int(input()) + 1
ans = 0

for a, b, c in product(range(1, k), repeat=3):
    ans += gcd(gcd(a, b), c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
K = int(input()) + 1
ABC = itertools.product(range(1, K), repeat=3)
ans = 0

for i in ABC:
    tmp = i[0]
    for j in range(1, 3):
        tmp = math.gcd(tmp, i[j])
    ans += tmp

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())
S=0
for i in range(1,K+1):
    for j in range(1,K+1):
        s=gcd(i,j)
        for k in range(1,K+1):
            S += gcd(s,k)

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
import math
n = int(input())
scores = []
for a, b, c, in list(product(range(1, n+1), repeat=3)):
    gcd_ab = math.gcd(a, b)
    score = math.gcd(gcd_ab, c)
    scores.append(score)
print(sum(scores))

Submission status: Time Limit Exceeded

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

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
from functools import reduce
# import math

def gcd(a, b):
  while b:
    a, b = b, a % b
  return a
  
def gcd_three(tup):
  return reduce(lambda a, b: gcd(a, b), tup)


K = int(input())
lst = range(1, K+1)
Sum = 0

for tup in product(lst, lst, lst):
  Sum += gcd_three(tup)
  
print(Sum)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
from functools import reduce
import math
 
def gcd(tup):
  return reduce(lambda a, b: math.gcd(a, b), tup)


K = int(input())
lst = range(1, K+1)
memory = {}
Sum = 0


for tup in product(lst, lst, lst):
  if str(sorted(tup)) in memory.keys():
    Sum += memory[str(sorted(tup))]
  else:
    memory[str(sorted(tup))] =gcd(tup)
    Sum += memory[str(sorted(tup))]
  
print(Sum)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
from functools import reduce
import math
 
def gcd(tup):
  return reduce(lambda a, b: math.gcd(a, b), tup)


K = int(input())
lst = range(1, K+1)
Sum = 0

for tup in product(lst, lst, lst):
  Sum += gcd(tup)
  
print(Sum)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
import fractions
import itertools
A = list(itertools.product(range(1,K+1),repeat=3))
ans = 0
for i in A:
    num = i[0]
    for j in range(1,3):
        num = fractions.gcd(num,i[j])
    ans += num
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())

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
k=int(input())

sum_num=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1,k+1):
      s=np.gcd.reduce([i,j,l])
      sum_num+=s
      
print(sum_num)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
readline = sys.stdin.readline


def main():
    k = int(readline().rstrip())
    kSum = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                kSum += gcd(a, b, c)
    print(kSum)


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


if __name__ == '__main__':
    main()

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

k = int(input())
comb = list(itertools.combinations_with_replacement([i for i in range(1,k+1)], 3))
ans = 0
for a,b,c in comb:
  n = a
  while n > 0:
    if a%n == 0 and b%n == 0 and c%n == 0:
      if len(set([a,b,c])) == 3:
        ans += 6 * n
      elif len(set([a,b,c])) == 2:
        ans += 3 * n
      else:
        ans += n
      break
    n -= 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

k = int(input())
ans = 0

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

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

Submission status: Time Limit Exceeded

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

def gcd (*numbers):
    return reduce(math.gcd, numbers)
    def  gcd_list (numbers):
        return reduce(math.gcd, numbers)
ans = 0

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

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

print(ans)

Submission status: Time Limit Exceeded

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



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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
import fractions
import functools
k = int(input())
h_list = []
 
 
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            h_list.append([i,j,l])
 
sum = 0
for i in range(len(h_list)):
    a = fractions.gcd(h_list[i][0], h_list[i][1])
    sum += fractions.gcd(a,h_list[i][2])
 
print(sum)