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
import itertools

K = int(input())

array = [i for i in range(1, K + 1)]

total = 0
for v in list(itertools.product(array, repeat=3)):
    total += math.gcd(v[0], math.gcd(v[1], v[2]))

print(total)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

N = int(input())

I = range(1, N+1)
J = range(1, N+1)
K = range(1, N+1)

count = 0

for i, j, k in product(I, J, K):
    count = count + gcd(i, j, k)

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import math
import itertools
from functools import reduce

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


if __name__ == "__main__":

    k = int(input())
    ans = 0

    num = list(range(1, k+1))
    comb = list(itertools.product(num, repeat=3))


    for i in range(len(comb)):
        ans += gcd(comb[i])

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import bisect

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

def query_gcd_3(a, b, c):
    return query_gcd(query_gcd(a, b), c)

def main():
    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 += query_gcd_3(i, j, k)
    print(ans)

if __name__ == "__main__":
    main()

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
    l = [i for i in range(1,k+1)]
    p_list = list(itertools.combinations_with_replacement(l,3))
    for i in p_list:
        ans += gcd(gcd(i[0],i[1]),i[2])*(6//math.factorial((4-len(set(i)))))
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
import itertools

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
  
K = int(input())

ans = 0
for comb in itertools.product(range(1, K+1), repeat=3):
    ans += gcd(*comb)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input().split()[0])

num_gcd = {}

def gcd_args(i, j, k):
    if (i, j, k) in num_gcd:
        return num_gcd[(i, j, k)]
    else:
        num = math.gcd(math.gcd(i, j), k)
        num_gcd[(i, j, k)] = num
        return num

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

n = int(input())

gcd_dic = {}
ans = 0
for i in range(1, n + 1):
    if i == 1:
        ans += n ** 2
        continue
    for j in range(1, n + 1):
        if i == 1:
            ans += n
            continue
        for k in range(1, n + 1):
            if i == 1:
                ans += 1
                continue
            comb = tuple(sorted([i, j, k]))
            if comb not in gcd_dic:
                gcd_dic[comb] = gcd(gcd(i, j), k)
            ans += gcd_dic[comb]
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
import itertools as itr

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

n = int(input()) 
aa = list(range(1, n+1 ))
bb = list(range(1, n+1))
cc = list(range(1, n+1))


for i in range(1):
    sum1 = 0
    for a,b,c in itr.product(aa,bb,cc):
        sum1+= gcd(a,b,c)
    print(sum1)

Submission status: Time Limit Exceeded

Solution code:

import fractions
K=int(input())
ans=0

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import math
import itertools

if __name__ == "__main__":
    K = int(input())+1
    ret = 0
    for a, b, c in itertools.product(range(1,K), range(1,K), range(1,K)):
        ret += reduce(math.gcd, [a,b,c])
    print(ret)

Submission status: Time Limit Exceeded

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

l = [[-1 for _ in range(k+1)] for _ in range(k+1)]

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):
        if l[x1][x2] == -1:
          ans = fractions.gcd(x1,x2)
        else:
          ans = l[x1][x2]
        if l[ans][x3] == -1:
          ans = fractions.gcd(ans,x3)
        else:
          ans = l[ans][x3]
        
        sum += ans
 
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

K = int(sys.stdin.readline())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

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())
L = [(a, b, c) for a in range(1, k+1) for b in range(1, k+1) for c in range(1, k+1)]
ans = 0
for l in L: ans += gcd_list(l)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

n = int(input())
temp = []
ans = 0

for i in range(1, n+1):
    for j in range(1, n+1):
      temp.append(gcd(i,j))

for temp_i in temp:
  for k in range(1, n+1):
    ans += gcd(temp_i, k)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
import itertools

def calc(a,b,c):
    x=gcd(a,b)
    y=gcd(x,c)
    return y

n=int(input())

A=list(itertools.product(range(1,n+1), repeat=3))

D={}
for i in A:
    mat=tuple(sorted(i))
    if mat in D:
        D[mat]+=1
    else:
        D[mat]=1

ans=0
for a,b,c in D:
    ans+=calc(a,b,c)*D[(a,b,c)]
print(ans)

Submission status: Time Limit Exceeded

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


k = int(input())

s = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for x in range(1, k+1):

            s += gcd(i, gcd(j, x))

print(s)

Submission status: Time Limit Exceeded

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

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from math import gcd


k = int(input())
l = range(1, k+1)
s = 0

for a in l:
    for b in l:
        for c in l:
            t = [a, b, c]
            g = reduce(gcd, t)
            s += g
            
print(s)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from sklearn.utils.extmath import cartesian
 
k = int(input())
ls = [i for i in range(1, k+1)]
arr = cartesian([ls,ls,ls])
 
temp = np.gcd(arr[:, 0], arr[:, 1])
temp = np.gcd(temp, arr[:, 2])
print(sum(temp))

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

Submission status: Time Limit Exceeded

Solution code:

def q3():
    import math
    k = int(input())
    sum_n = 0
    gcd_2_dict = {}
    gcd_3_dict = {}

    def gcd(n1, n2):
        if n1 < n2:
            sorted_nums = tuple([n1, n2])
        else:
            sorted_nums = tuple([n2, n1])
        if sorted_nums in gcd_2_dict:
            return gcd_2_dict[sorted_nums]
        gcd_num = math.gcd(n1, n2)
        gcd_2_dict[sorted_nums] = gcd_num
        return gcd_num

    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                sorted_nums = tuple(sorted([a, b, c]))
                if sorted_nums in gcd_3_dict:
                    gcd_num = gcd_3_dict[sorted_nums]
                else:
                    gcd_num = gcd(gcd(sorted_nums[0], sorted_nums[1]), sorted_nums[2])
                    gcd_3_dict[sorted_nums] = gcd_num
                sum_n += gcd_num

    print(sum_n)

q3()

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  
k = int(input())
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
from functools import reduce
n = int(input())
c = 0
def gcd(*numbers):
    return reduce(math.gcd, numbers)
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            c += gcd(i,j,k)

print(c)

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

Submission status: Time Limit Exceeded

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

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            #print(a, b, c)
            ans+=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 l in range(1,k+1):
            ans = 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)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
n=int(input())
g=0
for i in range(1,n+1):
    for j in range(1,n+1):
        for h in range(1,n+1):
            f=gcd(i,j,h)
            g=g+f
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):
        t = gcd(i,j)
        for k in range(1, K+1):
            ans += gcd(k,t)

print(ans)

Submission status: Time Limit Exceeded

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

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

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


N = II()
l = []
for i in range(1,N+1):
    l.append(i)
ans=0

num = 3 #生成するビット数
bit_list = list(itertools.product(l, repeat=num))

for L in bit_list:
    ans += gcd_list(L)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

n = int(input())
t = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            t += gcd(i, j, k)
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()) 
a=0
for i in range(1,K+1):
  for j in range(1,K+1):
    for l in range(1,K+1):
      a=a+gcd(i,j,l)
print(a)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

def yakusu( val ):
  yaku = []
  yaku.append(val)
  for i in range( 1, val//2+1 ):
    if( val%i == 0 ):
    	yaku.append( i )
  return yaku
  
ndict = {}

for i in range(1,k+1):
  yaku=yakusu(i)
  yaku.sort(reverse=True)
  ndict[i] = yaku

#print(ndict)
total = 0 
for i in range(1,k+1):
  ilist = ndict[i]
  for j in range(1,k+1):
    jlist = ndict[j]
    ijlist = []
    for il in ilist:
      if( il in jlist ):
         ijlist.append(il )
    for l in range(1,k+1):
      llist = ndict[l]
      for ijl in ijlist:
      	if( ijl in llist ):
          total += ijl
          break
print(total)

Submission status: Time Limit Exceeded

Solution code:
import time
mem = {}
def gcd(a, b):
    global mem
    if (a, b) not in mem and (b, a) not in mem:
        mem[(a, b)] = a if b == 0 else gcd(b, a%b)
        mem[(b, a)] = mem[(a, b)]
    return mem[(a, b)]

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

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())
A = 0

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

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

print(A)

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

    old_dict = {}

    for l in itertools.product(num_li, repeat=3):

        str_l = str(sorted(l))

        if str_l in old_dict:
            ans += old_dict[str_l]
        else:
            num = gcd(l[0], l[1], l[2])
            old_dict[str_l] = num
            ans += num

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

import numpy as np
import math
K = int(input())
memo = np.zeros((K,K),int)
s = 0
for i in range(K):
  for j in range(K):
    for k in range(K):
      if memo[i][j] != 0:
        if memo[memo[i][j]-1][k] != 0:
          s += memo[memo[i][j]-1][k]
        else:
          memo[memo[i][j]-1][k] = math.gcd(memo[i][j],k+1)
          memo[k][memo[i][j]-1] = memo[memo[i][j]-1][k]
          s += memo[k][memo[i][j]-1]
      else:
        
        memo[i][j] = math.gcd(i+1,j+1)
        memo[j][i] = memo[i][j]
        if memo[memo[i][j]-1][k] != 0:
          s += memo[memo[i][j]-1][k]
        else:
          memo[memo[i][j]-1][k] = math.gcd(memo[i][j],k+1)
          memo[k][memo[i][j]-1] = memo[memo[i][j]-1][k]
          s += memo[k][memo[i][j]-1]
print(s)

Submission status: Time Limit Exceeded

Solution code:
import math 

K = int(input())
mymemo =  [ [float('INF') for k in range(K+1) ] for kk in range(K+1) ]
#print(mymemo)

mysum = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            if mymemo[a][b] != float('INF'):
                mygcd = mymemo[a][b]
            else:
                mygcd = math.gcd(a,b)
                mymemo[a][b] = mygcd
            if mymemo[mygcd][c] != float('INF'):
                mygcd2 = mymemo[mygcd][c]
            else:
                mygcd2 = math.gcd(mygcd,c)
                mymemo[mygcd][c] = mygcd2
            mysum += mygcd2
            #print(a, b,c, mygcd)
            #print(mymemo)
print(mysum)

Submission status: Time Limit Exceeded

Solution code:
import math

result = 0
K = int(input())
for i in range(K):
  for j in range(K):
    for k in range(K):
      a = i+1
      b = j+1
      c = k+1
      num = math.gcd(a,b)
      num2 = math.gcd(num,c)
      result += num2
print(result)

Submission status: Time Limit Exceeded

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

for x in range(1,k+1):
    for y in range(1,k+1):
        for z in range(1,k+1):
            ans += gcd(x,y,z)
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

total = 0

for i in range(1, K + 1):
    for q in range(1, K + 1):
        for w in range(1, K + 1):
            num = 0
            for e in range(1, 201):
                if i % e == 0 and q % e == 0 and w % e == 0:
                    if num <= e:
                        num = e
            total = total + num

print(total)

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())

memo = [[[None]*(k+1) for i in range(k+1)] for j in range(k+1)]

ans = 0
for p in range(1,k+1):
  for q in range(1,k+1):
    for r in range(1,k+1):
      a = sorted([p,q,r])
      if memo[a[0]][a[1]][a[2]] == None:
        memo[a[0]][a[1]][a[2]] = math.gcd(p,math.gcd(q,r))
      ans += memo[a[0]][a[1]][a[2]]
      
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)


K = int(input()) + 1
K_a = K
K_b = K
K_c = K
sum = 0

for x in range(1, K_a):
    for y in range(1, K_b):
        for z in range(1, K_c):
            sum += gcd(x, y, z)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
# K, N = map(int, input().split())
# a = list(map(int, input().split()))

# N = int(input())

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
ans=0
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1,k+1):
      ans=ans+gcd(i,gcd(j,l))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
total = 0

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

    while(b > 0):
        r = a % b
        a = b
        b = r

    return a


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


print(total)

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

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)

S=0
for l in range(K):
    for m in range(K):
        for n in range(K):
            S+=gcd(l+1, m+1, n+1)
            #print(l+1, m+1, n+1,gcd(l+1, m+1, n+1))
print(S)

Submission status: Time Limit Exceeded

Solution code:
import sys, re
import math
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
 
# 整数リストを連結表示    print(''.join(map(str, list)))
 
# -*- coding: utf-8 -*-
 
k = INT()
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:
import itertools as it
import math

K = int(input())

gcd_list = []
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            gcd_ = math.gcd(math.gcd(i, j), k)
            gcd_list.append(gcd_)
print(sum(gcd_list))

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b,c):
  g=max(a,b,c)
  while a%g!=0 or b%g!=0 or c%g!=0:
    g-=1
  return g
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 math


def get_gcd(n_1, n_2, n_3):
    string_n = str(n_1) + " " + str(n_2)+" "+str(n_3)
    a = list(map(int, string_n.split()))
    N = 3
    ans = a[0]
    for i in range(1, N):
        ans = math.gcd(ans, a[i])
    return ans


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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())  #スペース抜きの複数行,１文字ずつ
import math
from functools import reduce

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

A = []
A.append((K-1)*3)
A.append(((K-1)**2)*3)
A.append(1)
#print(A)
for i in range(2, K+1):
    for j in range(2, K+1):
        for k in range(2, K + 1):
#            if i != 1 and j != 1 and k != 1:
                #print(i, j, k)
                #print(gcd_list([i, j, k]))
                A.append(gcd_list([i, j, k]))

#print(A)
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K = int(input())
ans = 0

for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            min_num = min(a, b, c)
            if a % min_num == 0 and b % min_num == 0 and c % min_num == 0:
                ans += min_num
            else:
                ans += gcd(a, b, c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

k = int(input())
ans = 0

a = [(i+1,j+1,l+1) for i in range(k) for j in range(k) for l in range(k)]

for i in a:
  ans += (gcd(gcd(i[0],i[1]),i[2]))


print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import fractions

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

def gcd_(a, b):
  if (b == 0):
    return a
  return gcd(b, a % b)
 
sum = 0
K = int(input())
 
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      sum += gcd(i,j,k)
      
print(sum)

Submission status: Time Limit Exceeded

Solution code:

import fractions
from functools import reduce


k = int(input())

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

k += 1
ans = 0

for i in range(1,k):
    for j in range(i,k):
        #print(i,j)
        if i == j:
            ans += gcd(i,j)
        else:
            ans += gcd(i,j)*6

for i in range(1,k):
    for j in range((i+1),k):
        for h in range((j+1),k):
            #print(i,j,h)
            ans += gcd(i,j,h)*6


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import fractions

def in_ctrl():
    _input = [_.rstrip() for _ in sys.stdin.readlines()]
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    K = int(_input[0])
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    return K


def out_ctrl(s):
    print(s)


if __name__ == "__main__":
    K = in_ctrl()
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 0
    for a in range(1,K+1):
        cnt += a
        for b in range(a+1,K+1):
            ans = fractions.gcd(a,b)
            cnt += 6*ans
            for c in range(b+1,K+1):
                cnt += 6*fractions.gcd(ans, c)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    out_ctrl(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import fractions
from functools import reduce


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


k = int(input())
n = []
for i in range(1, k+1):
    n.append(i)
res = 0
for v in itertools.product(n, repeat=3):
    res += gcd(v[0], v[1], v[2])
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())
i = 0

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
k=int(input())
r1=[]
sum=0
for l in range(1,k+1):
    for m in range(1,k+1):
        r1.append(gcd(l,m))

for i in range(len(r1)):
    for j in range(1,k+1):
        sum += gcd(r1[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)
 
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

t = 0
k= int(input(''))+1
for l in range(1,k):
    for m in range(1,k):
        for n in range(1,k):
            if l==m and m==n:
                t+=l
            else:
                t+= gcd_list([l,m,n])
#            print("{}/{}/{} -> {}".format(l,m,n,gcd(l,m,n)))
 
print(t)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K = int(input())

a = []
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            a.append([i,j,k])

ans = 0
for i in a:
    ans += gcd(i)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import math
import itertools
from functools import reduce

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


if __name__ == "__main__":

    k = int(input())
    ans = 0

    num = list(range(1, k+1))
    comb = list(itertools.product(num, repeat=3))


    for i in range(len(comb)):
        ans += gcd(comb[i][0], comb[i][1], comb[i][2])

    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 s in range(1,k+1):
    for t in range(1,k+1):
        for u in range(1,k+1):
            ans += gcd(s,t,u)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
def gcd(x,y):
    if x < y:
        x,y = y,x
    if y == 0:return x
    return gcd(y,x%y)
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)