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 fractions
K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        ab = fractions.gcd(i,j)
        if ab == 0:
            continue
        for k in range(1,K+1):
            ans += fractions.gcd(ab,k)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
from functools import reduce
# import itertools
from collections import defaultdict

a=int(input())

def ggcd(*numbers):
    return reduce(gcd, numbers)

sum=0

for x in range(1,a+1):
    for y in range(1,a+1):
        if x == 1 and y==1 : sum+=(1*a);continue
        for z in range(1,a+1):
            if x==y==z:
                sum+=x
            else:
                if(x == y or y==z):
                    sum += gcd(x, z)
                elif(x==z):
                    sum += gcd(x, y)
                else:
                    sum += ggcd(x, y,z)
                    

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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:
from itertools import product
from functools import reduce
from math import gcd
k = int(input())
ans = 0
for abc in product([i for i in range(1, k+1)], repeat=3):
    ans += reduce(gcd, abc)
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 n in range(1,k+1):
            ans += math.gcd(i,math.gcd(j,n))
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
import itertools



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


a = int(input())
ans = 0
nums = []
for i in range(1, a+1):
    nums.append(i)

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

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 itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
from fractions import gcd
from copy import deepcopy
import math
import queue
#import sympy as syp(素因数分解とか)
Mod = 1000000007
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main(): #startline-------------------------------------------
    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 += gcd(gcd(i,j),l)

    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
def gcd(*number):
    return reduce(math.gcd, number)
n = int(input())
a, b, c = 1, 1, 1
sum = 0
while True:
    sum += gcd(a, b, c)
    if n > c:
        c += 1
    elif n == c and n == b and n == a:
        break
    elif n == c and n == b:
        a += 1
        b = 1
        c = 1
    elif n == c:
        b += 1
        c = 1
print(sum)

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(i, math.gcd(x, z))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

def main():
    #n, k = map(int,input().split())
    k = int(input())
    lists = []
    sum = 0
    for i in range(1,k+1):
        for j in range(1,k+1):
            for l in range(1,k+1):
                #print(i,j,l)
                sum = sum + gcd(i,j,l)
    print(sum)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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
n = int(input())
def gcd(i,j,k):
    return math.gcd(math.gcd(i,j),k)
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 fractions import gcd
n = int(input())
g = 0
for i in range (1, n+1):
  for j in range (1, n+1):
    for k in range (1, n+1):
      g  += gcd(gcd(i,j),k)
print(g)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

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

Submission status: Time Limit Exceeded

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

print(int(n))

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from fractions import gcd
input = sys.stdin.readline

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())
sumGCD = K * K * K
for a in range(2, K + 1, 1):
    for b in range(2, K + 1, 1):
        for c in range(2, K + 1, 1):
            arr = [a, b, c]
            gcdNum = math.gcd(math.gcd(a, b), c)
            # if gcdNum != 1:
            # print(arr)
            # print(gcdNum)
            sumGCD += gcdNum - 1
print(sumGCD)

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import gcd, ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
c = 0
K = INT()
ans = 0
 
for i in range(1, K + 1):
    for j in range(1, K + 1):
        a = gcd(i, j)
        for k in range(1, K + 1):
            b = gcd(a, k)
            ans += b
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()) + 1
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
from fractions import gcd
from copy import deepcopy
import math
import queue
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main(): #startline-------------------------------------------
    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 += gcd(gcd(i,j),l)

    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
import math

#n = map(int,input().split())

k = int(input())


def gcd(a,b):
    if a > b:
        a , b = b , a

    # q = b / a
    r = b % a

    if r == 0:
        return a
    else:
        return gcd(a,r)
    

sum = 0



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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
K = int(input())

# lcm & gcd not math library
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
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(gcd(i, j), k)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
def gcd(*number):
    return reduce(math.gcd, number)
n = int(input())
a, b, c = 1, 1, 1
sum = 0
list_number = []
while True:
    list_number.append(gcd(a, b, c))
    if n > c:
        c += 1
    elif n == c and n == b and n == a:
        break
    elif n == c and n == b:
        a += 1
        b = 1
        c = 1
    elif n == c:
        b += 1
        c = 1
for i in list_number:
    sum = sum + i
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
 
def main():
    K = int(input()) + 1
 
    def get_gcd(a, b, c):
        tmp = gcd(a, b)
        return gcd(tmp, c)
 
    result = 0
    for c in range(1, K):
        for b in range(1, K):
            for a in range(1, K):
                result += get_gcd(a, b, c)
    print(result)
 
 
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:
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
n = int(input())
ans = 0
for a in range(1,n+1):
    for b in range(1,n+1):
        for c in range(1,n+1):
            ans += math.gcd(a,math.gcd(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 math import gcd
 
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):
      x=gcd(i,j)
      sum += gcd(x,k)
print(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 s in range(1,k+1):
            ans += math.gcd(math.gcd(i,j),s)

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)
count=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):
			count+=(gcd_list([i,j,k]))
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
 
K = int(input())
 
lis = [i for i in range(1,K+1)]
a = []
 
for i in lis:
    for j in lis:
        for k in lis:
            a.append([i,j,k])
gcd_list = []
for i in a:
    e,f,g = map(int,i)
    e_f = math.gcd(e,f)
    e_g = math.gcd(e,g)
    e_f_g = math.gcd(e_f,e_g)
    gcd_list.append(e_f_g)
print(sum(gcd_list))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
import math

#n = map(int,input().split())

k = int(input())


def gcd(a,b):
    if a > b:
        a , b = b , a

    # q = b / a
    r = b % a

    if r == 0:
        return a
    else:
        return gcd(a,r)
    

sum = 0



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

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
n = int(input())
c = itertools.product(range(1, n + 1), repeat=3)
t = 0
for l in c:
    s = math.gcd(l[0], math.gcd(l[1], l[2]))
    t += s
print(t)

Submission status: Time Limit Exceeded

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

def euclidean_abc(a, b, c):
    return euclidean(euclidean(a,b),euclidean(b,c))

N = int(input())

s = 0

for i in range(N):
    for j in range(N):
        for k in range(N):
            s +=euclidean_abc(i+1,j+1,k+1)

print(s)

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

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
from functools import reduce

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

Submission status: Time Limit Exceeded

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

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

s = 0
for a in range(1,K+1):
    for b in range(1,a+1):
        for c in range(1,b+1):
            if a == b and b == c:
                s += gcd(a,b,c)
            elif a == b or a == c or b == c:
                s += gcd(a,b,c) * 3
            else:
                s += gcd(a,b,c) * 6
print(s)

Submission status: Time Limit Exceeded

Solution code:
# coding=UTF-8
import numpy as np
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 += np.gcd.reduce([i, j, l])
print(int(sum))

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b,c):
    for i in range(1,10**5):
        if a%i==0 and b%i==0 and c%i==0:
            d=i
    return d
        
a=int(input())
x=0
for i in range(1,a+1):
    for j in range(1,a+1):
        for k in range(1,a+1):
            x+=gcd(i,j,k)

print(x)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
 
K=int(input())
 
S=0
for a in range(1,K+1):
    for b in range(1,K+1):
        calc=np.gcd(a,b)
        for c in range(1,K+1):
                S+=np.gcd(calc,c)
 
print(S)

Submission status: Time Limit Exceeded

Solution code:

import itertools
import numpy as np
from numba import jit


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


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


N = input()
a = [int(N) for k in range(3)]
range_list = list(map(lambda x: range(1, x+1), a))
prd_list = itertools.product(*range_list)

# prd_set = ((s[0] + 1, ))

gcds = [gcd3(*prd) for prd in prd_list]

s = np.sum(gcds)

print(s)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
import math

#n = map(int,input().split())

k = int(input())


def gcd(a,b):
    if a > b:
        a , b = b , a

    # q = b / a
    r = b % a

    if r == 0:
        return a
    else:
        return gcd(a,r)
    

sum = 0



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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
import math
ans=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)
            ans+=math.gcd(a,l)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

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):
            l = [a, b, c]
            ans = l[0]
            for i in range(1,3):
                ans = math.gcd(ans, l[i])
            sum_gcd = sum_gcd + ans

print(sum_gcd)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
from functools import reduce

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

k = int(input())

ans = 0 

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

Submission status: Time Limit Exceeded

Solution code:
import fractions
k = int(input())
cnt = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        tmp = fractions.gcd(i,j)
        for m in range(1,k+1):
            cnt += fractions.gcd(m,tmp)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations, combinations,combinations_with_replacement,product
import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
    
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

def main():
    #n, k = map(int,input().split())
    k = int(input())
    lists = []
    for i in range(k):
        for j in range(k):
            for l in range(k):
                lists.append((i+1,j+1,l+1))
    
    #for v in combinations_with_replacement(lists,3):
    #    print(v)
    #lists = list(combinations_with_replacement(lists,3))
    #lists2 = set(lists)
    #print(lists)
    #lists2 = [i[0]*100+i[1]*10+i[2] for i in lists]
    #print(lists2)
    k = 0
    for i in lists:
        k = k + gcd(i[0],i[1],i[2])
    print(k)
    """
    koubai = 0
    for i in lists:
        if len(set(i))==1:
            koubai = koubai + gcd(i[0],i[1],i[2])
            #print(koubai)
        elif len(set(i))==2:
            koubai = koubai + 3*gcd(i[0],i[1],i[2])
        else:
            koubai = koubai + 6*gcd(i[0],i[1],i[2])
            #print(koubai)
    print(koubai)
    """



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b):
  while b:a,b=b,a%b
  return a
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(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:
k = int(input())
import math
def gcd(a,b,c):
  return (math.gcd(a, math.gcd(b, c)))
tsum=0
for a in range (1,k+1):
  for b in range (1,k+1):
    for c in range (1,k+1):
      tsum+= gcd(a,b,c)
print(tsum)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

K = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
# a,bの最大公約数


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


gcdl = [[0]*k*2 for _ in range(k*2)]
for a in range(1, k+1):
    for b in range(1, k+1):
        gcdl[a][b] = gcd(a, b)

ansl = [[[-1]*k*2 for _ in range(k*2)] for _ in range(k*2)]
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            if ansl[a][b][c] == -1:
                t = gcd(c, gcdl[a][b])
                ansl[a][b][c] = t
                ansl[a][c][b] = t
                ansl[b][a][c] = t
                ansl[b][c][a] = t
                ansl[c][b][a] = t
                ansl[c][a][b] = t
            else:
                t = ansl[a][b][c]
            ans += t
print(ans)

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:
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:
N = int( input() )

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

Ans = 0
for a in range( 1 , N + 1 ):
    for b in range( 1 , N + 1 ):
        for c in range( 1 , N + 1 ):
            Ans += gcd(a,b,c)
print( Ans )

Submission status: Time Limit Exceeded

Solution code:
import math
k=int(input())
s=0
for x in range(1,k+1):
  for y in range(1,k+1):
    for z in range(1,k+1):
      s+=math.gcd(x,math.gcd(y,z))
print(s)

Submission status: Time Limit Exceeded

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

from functools import reduce
def gcd_multi(num_list):
    return reduce(math.gcd, num_list)

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_multi([i,j,k])
print(answer)

Submission status: Time Limit Exceeded

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


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):
            if i==1 or j==1 or k ==1:
                ans += 1
            else:
                ans += gcd(i,j,k)

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

if __name__ == "__main__":
    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:
k = int(input())
import math
ans = 0
for i in range(1,k+1):
  for j in range(1,k+1):
    for x in range(1,k+1):
      ans += math.gcd(i,math.gcd(j,x))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
k = int(input())
l = [[i,j,m] for i in range(1,k+1) for j in range(1,k+1) for m in range(1,k+1)]
ans = 0
for i in range(len(l)):
    ans += math.gcd(l[i][2],math.gcd(l[i][0],l[i][1]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from numpy import gcd 
k = int(input())
sss = 0
for a in range(1,k+1):
    for b in range(a+1,k+1):
        tmp = gcd(a,b)
        sss += 6*tmp
        for c in range(b+1,k+1):
            sss += 6*gcd(tmp,c)
sss += k*(k+1)//2
print(sss)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce

K = int(input())

res = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            tmp = [i,j,k]
            res += reduce(gcd,tmp)
print(res)

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())

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

    
print(total)