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


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


n = int(input())
num = 0

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

print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# your code goes here
n = int(input())
from itertools import combinations
def gcd(p,q):
	while q:
		p,q = q, p%q
	return p

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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


K=int(input())

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)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
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_array = np.zeros((k, k, k), dtype = np.int)

for i in range(k):
  for j in range(k):
    for h in range(k):
      if ans_array[i, j, h] == 0:
        m_gcd = gcd(i+1, j+1, h+1)
        ans_array[i, j, h] = m_gcd
        if ans_array[i, h, j] == 0:
          ans_array[i, h, j] = m_gcd
        if ans_array[h, j, i] == 0:
          ans_array[h, j, i] = m_gcd

# print(ans_array)
ans = np.sum(ans_array)

print(ans)

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 math
def GCD(a,N):
    gcd = a[0]
    for i in range(1, N):
        gcd = math.gcd(gcd, a[i])
    return gcd


k = int(input())
# h, w = map(int, input().split())
# a = list(map(int, input().split()))
ans = 0
L = []
for i in range(1, k+1):
    for j in range(1, k+1):
        for l in range(1, k+1):
            if i==1 or j==1 or l==1:
                ans += 1
            else:
                ans += GCD([i,j,l], 3)

print(ans)

Submission status: Time Limit Exceeded

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

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
a = [i + 1 for i in range(k)]
b = [i + 1 for i in range(k)]
c = [i + 1 for i in range(k)]

for x in a:
    for y in b:
        for z in c:
            ans += gcd(x, y, z)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
K = int(input())
s = []
def gcd(*numbers):
    return reduce(math.gcd, numbers)
for i in range(K):
    for j in range(K):
        for k in range(K):
            s.append(gcd(i+1,j+1,k+1))
print(sum(s))

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
K=int(input())
A=[]
B=[]
C=[]
for i in range(1,K+1):
  A.append(i)
  B.append(i)
  C.append(i)

ans=[]
for a,b,c in (itertools.product(A,B,C)):
    x=math.gcd(a,b)
    y=math.gcd(x,c)
    ans.append(y)
    

    
print(sum(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 a in range(K):
	for b in range(K):
		for c in range(K):
			sum += gcd(a+1, b+1, c+1)
print(sum)

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

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


k = int(input())
koho = list(range(1,k+1))*3
ans = 0
for i in set(list(itertools.combinations(koho, 3))):
    ans += gcd(list(i))
      
print(ans)

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

print(count)

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

k = int(input())

def gcd2(*numbers):
    return reduce(math.gcd,numbers)
sum = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            #print(gcd2(a,b,c))
            sum = sum + gcd2(a,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)
n=200
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:
import math
from functools import reduce

def gcd(a,b,c):
    d = math.gcd(a,b)
    return math.gcd(d,c)
cnt =0
K = int(input())
for i in range(1,K+1):
    for m in range(1,K+1):
        for u in range(1,K+1):
            cnt+= gcd(i,m,u)
print(cnt)

Submission status: Time Limit Exceeded

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

n = int(input())

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

print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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
        return z

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
from functools import reduce
#K = int(input())
K = 200
def gcd_List(List):
  return reduce(gcd,List)
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_List([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 k in range(1, K+1):
            num = gcd(i, j, k)
            ans = ans + num

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 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())
cnt = 0
tmp = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            tmp = math.gcd(a, b)
            cnt += math.gcd(tmp, c)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

import math 
from functools import reduce

sum = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            sum += reduce(math.gcd, (a, 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)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

n = int(input())
sum = 0

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

K = int(input())
list_a = []

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

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

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            list_a.append(gcd(i, j, k))

print(sum(list_a))

Submission status: Time Limit Exceeded

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

sum = 0
for x1 in range(1,k+1):
  for x2 in range(1,k+1):
    for x3 in range(1,k+1):
      for i in range(1, 2):
        ans = fractions.gcd(x1,x2)
        ans = fractions.gcd(ans,x3)
        sum += ans

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import gcd

def triplet_gcd(a,b,c):
    if a == b == c:
        return a
    s = set((a, b, c))
    if len(s) == 2:
        return gcd(*s)
    else:
        return gcd(gcd(a, b), c)

K = int(sys.stdin.readline().rstrip())
ans = sum([triplet_gcd(a, b, c) for a in range(1, K+1) for b in range(1, K+1) for c in range(1, K+1)])

print(ans)

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import math
import fractions

n = int(stdin.readline().rstrip())

cnt = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            a = math.gcd(i+1, j+1)
            b = math.gcd(a, k+1)
            cnt += b

print(cnt)

Submission status: Time Limit Exceeded

Solution code:

gcd_dict = {}

def gcd(a,b):
    if (a>=b):
        n1 = a
        n2 = b
    else:
        n1 = b
        n2 = a
    if ((n1,n2) in gcd_dict.keys()):
        return gcd_dict[(n1,n2)]
    r = n1%n2
    while(r>0):
        n1 = n2
        n2 = r
        r = n1%n2
    gcd_dict[(n1,n2)] = n2
    return n2

K = int(input())

ret = 0

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

print(ret)

Submission status: Time Limit Exceeded

Solution code:
import math
import functools
import itertools


@functools.lru_cache
def gcd(p):
    return math.gcd(math.gcd(p[0], p[1]), p[2])


# 文字列1行
K = int(input().strip())
Kr = range(1, K+1)

items = itertools.product(Kr, Kr, Kr)
sum_ = 0
for p in items:
    sum_ += gcd(p)
print(sum_)

Submission status: Time Limit Exceeded

Solution code:
n = int ( input() )

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

dicts = {}
total = 0 
for i in range(1, n + 1):
    for j in range(1, n + 1):
        for k in range(1, n + 1):
            strin = str(i) + "," + str(j)
            if strin not in dicts:
                gh = find_gcd(i, j)
                strin3 = str(j) + "," + str(i)
                dicts[strin] = gh 
                dicts[strin3] = gh 
                
            else:
                gh = dicts[strin]
            
            strin2 = str(gh) + "," + str(k)
            
            if strin2 not in dicts:
                gh = find_gcd(gh, k)
                strin4 = str(k) + "," + str(gh)
                dicts[strin2] = gh 
                dicts[strin4] = gh 
            else:
                gh = dicts[strin2]
            
            
            total += gh 
print(total)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())+1
out = 0
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
for i in range(1,k):
    for i2 in range(1,k):
        for i3 in range(1,k):
            out += gcd(gcd(i,i2),i3)
print(out)

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

Submission status: Time Limit Exceeded

Solution code:
import math
from sys import stdin


def get_result(data):
    K = data[0]
    ans_list = []
    for i in range(K):
        for j in range(K):
            for k in range(K):
                ans = math.gcd(i+1, j+1)
                ans = math.gcd(ans, k+1)
                ans_list.append(ans)
    return sum(ans_list)


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)

Submission status: Time Limit Exceeded

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

import itertools

import math

from functools import reduce

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

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

    num_li = list(range(1, k+1))

    ans = 0

    for a,b,c in itertools.product(num_li, repeat=3):
        ans += gcd(a,b,c)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from functools import reduce
import math

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

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

Submission status: Time Limit Exceeded

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

count=int(input())+1
sum=0

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

print(sum)

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


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


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

print(res)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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


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

Submission status: Time Limit Exceeded

Solution code:
import fractions
import functools

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

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

Submission status: Time Limit Exceeded

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

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

k = int(input())
out = 0
for i in range(k):
    a = i + 1
    for j in range(k):
        b = j + 1
        gcd2 = np.gcd(a, b)
        for m in range(k):
            c = m + 1
            out = out + np.gcd(c, gcd2)


print(out)

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:
K = int(input())
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
g = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            g += gcd(i,j,k)
print(g)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

ans = []

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

from itertools import product

for (x1, x2, x3) in product(list(range(1, k+1)), repeat=3):
    ans.append(gcd(gcd(x1, x2), x3))

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

Submission status: Time Limit Exceeded

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

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)
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
K=int(input())
ans=0
def gcd(a,b,c):
    a=math.gcd(a,b)
    return math.gcd(a,c)

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:
# -*- coding: utf-8 -*-
import math


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


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

    total = 0
    temp = {}
    for i in range(1, k + 1):
        for j in range(1, k + 1):
            for l in range(1, k + 1):
                join_str = "".join(sorted([str(i).zfill(3), str(j).zfill(3), str(l).zfill(3)]))
                gcd_val = temp.get(join_str, 0)
                if gcd_val == 0:
                    gcd_val = gcd(i, j, l)
                total += gcd_val

    return total


if __name__ == '__main__':
    print(main())

Submission status: Time Limit Exceeded

Solution code:


import itertools
import math
from functools import reduce

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

K = int(input())
lis = list(itertools.product(range(1, K+1), repeat=3))

ans=0
for x, y, z in lis:
    ans += gcd(x, y, z)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
import fractions

k =int(input())
#  =map(int,input().split())
#  =list(map(int,input().split()))
sum = 0

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

n = int(input())

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:

import math
K = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
import math
mxn = 200+11
inf = 10**18+1
arr = [[[-inf for i in range(mxn)]for k in range(mxn)] for j in range(mxn)]
def g(a,b,c):
    e = sorted([i,j,k])
    if arr[e[0]][e[1]][e[2]] == -inf:
        arr[a][b][c] = math.gcd(math.gcd(a,b), c)
        arr[b][a][c] = arr[a][b][c]
        arr[c][a][b] = arr[a][b][c]
        arr[c][b][a] = arr[a][b][c]
        arr[b][c][a] = arr[a][b][c]
        arr[a][c][b] = arr[a][b][c]
    return arr[a][b][c]


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):
            #a = sorted([i,j,k])
            #s += g(a[0],a[1],a[2])
            s+= g(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):
            ans1 = math.gcd(a, b)
            ans2 = math.gcd(ans1, c)
            ans += ans2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

N = int(input())
s = 0

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

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


print(s)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

# 整数を一つ入力
N = int(input())

res = 0

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest
import math
from functools import reduce

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

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    k=int(readline())
    #ss=readline().rstrip()
    #yn(1)
    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)



    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
k=int(input())
lis=[]
def gcd(a,b,c):
    d=math.gcd(a,b)
    return math.gcd(d,c)
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1, k+1):
            lis.append(gcd(i,j,l))
print(sum(lis))

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

s = 0
for h in range(1, k+1):
    for j in range(1, k+1):
        for k in range(1, k+1):
            s = s + gcd(gcd(h, j), gcd(h, k))

print(s)

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

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

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

for i in range(1, k+1):
    for m in range(1, k+1):
        for n in range(1, k+1):
            nums = [i, m, n]
            gcd_list.append(gcd(nums))

print(sum(gcd_list))

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 fractions as fr
k = int(input())
ans = (k+1)*k//2
for i in range(1, k+1):
  for j in range(1, k+1):
    if i == j:
      continue
    else:
      ans += 3*fr.gcd(i, j)
for i in range(1, k-1):
  for j in range(i+1, k):
    for l in range(j+1, k+1):
      te = fr.gcd(i,j)
      tee= fr.gcd(te,l)
      ans+= 6*tee
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(k):
    i += 1
    for j in range(k):
        j += 1
        for l in range(k):
            l += 1
            ans += gcd(i, j, l)

print(ans)

Submission status: Time Limit Exceeded

Solution code:

def gcd(a, b):
    if a < b:
        a, b = b, a
    r = a % b
    if r == 0:
        return b
    return gcd(r, 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):
            ans += gcd(gcd(a, b), c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:

def main():
    import math
    from functools import reduce
    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 += reduce(math.gcd,[i,j,l])
    print(s)        
            
if __name__ == "__main__":
    main()

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())
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
ans = 0
dic = {}
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            tmp = [a,b,c]
            tmp = list(sorted(tmp))
            moji = list(map(str,tmp))
            moji = " ".join(moji)
            try:
                dic[moji]
                ans += dic[moji]
            except:
                num = gcd(tmp[0],tmp[1],tmp[2])
                ans += num
                dic[moji] = num

print(ans)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

k = int(input())

ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            ans += reduce(math.gcd,[i,j,l])

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
def gcd(a,b):
    if a <b:
        a,b=b,a
    while a%b != 0:
        a,b= b,a%b
    return b
x=0
for i in range(1,K+1):
    for j in range(1,K+1):
        for l in range(1,K+1):
            x+=gcd(gcd(i,j),l)
print(x)

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())

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

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(k):
    for b in range(k):
        for c in range(k):
            # print(a+1, b+1, c+1)
            sum += gcd(a+1, b+1, c+1)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
sum = 0

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def gcd3(a,b,c):
    m = gcd(a,b)
    h = gcd(m,c)
    return h

N = int(input())
count = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            l=gcd3(i,j,k)
            count += l
print(count)