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:


n = int(input())
_MAX = 200

gcd_result = [ [ [ 0 for _ in range(_MAX+1)] for _ in range(_MAX+1)] for _ in range(_MAX+1) ]

ans = 0


from functools import lru_cache
from math import gcd

@lru_cache(maxsize=1000)
def calc(lst):
    p = 0
    for v in lst:
        if p == 0:
            p = v
        else:
            p = gcd(p, v)

    return p


for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            ls = [i, j, k]
            ans += calc(tuple(set(ls)))

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

# from collections import defaultdict


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


def reducef(x, y):
    return gcdd[(x, y)]


def gcd2(*numbers):
    return reduce(reducef, numbers)


K = int(input())
ans = 0
# gcdd=defaultdict()
gcdd = {}
for a in range(1, K + 1):
    for b in range(1, K + 1):
        if (a, b) not in gcdd:
            gcdd[(a, b)] = gcd(a, b)

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from fractions import gcd
inp=int(input())
total=0
for i in range(1,inp+1):
  for j in range(1,inp+1):
    for k in range(1,inp+1):
      total=total+reduce(gcd,(i,j,k))
print(total)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

K = int(input())

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

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

sigk = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            d = math.gcd(i,j)
            e = math.gcd(d,l)
            sigk += e

print(sigk)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
from functools import reduce

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

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

  ans = 0

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

  print(ans)



if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
from functools import reduce
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm_base(a, b):
    return (a * b) // gcd(a, b)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def main():
  k = int(input())
  ans = 0
  for a in range(1, k+1):
    for b in range(a, k+1):
      for c in range(b,k+1):
        if a==b and b==c:
          ans += gcd(gcd(a,b),c)
        elif a==b or b==c or c==a:
          ans += gcd(gcd(a,b),c) * 3
        else:
          ans += gcd(gcd(a,b),c) * 6
  print(ans)
  
  
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
import sys,math
import numpy as np

n=int(sys.stdin.readline())
#n,k=map(int,sys.stdin.readline().split())
#a=np.array(sys.stdin.readline().split(),dtype='int64')
#a=np.array([sys.stdin.readline().split() for i in range(n)],dtype='int64')
ans=0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            ans+=math.gcd(math.gcd(i,j),k)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

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

count=0
for i in range(1, K+1):
  for j in range(i, K+1):
    for k in range(j, K+1):
      if i == j and j == k:
        kake = 1
      elif i == j or j == k or i == k:
        kake = 3
      else:
        kake = 6
      count += gcd(i, j, k) * kake

print(count)

Submission status: Time Limit Exceeded

Solution code:
import math 

K  = int(input())
total  = 0

for s in range(1,K+1):
    for t in range(1,K+1):
        for u in range(1,K+1):
            # print(s,t,u,math.gcd(math.gcd(s,t),u))
            total +=math.gcd(math.gcd(s,t),u)
2
print(total)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
K = int(input())
ans = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce


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


K = int(input())

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

print(sum(hoge))

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
import fractions
ans = 0
for i in range(1,k+1):
         for j in range(i,k+1):
                  for l in range(j,k+1):
                           tmp = fractions.gcd(i,j)
                           tmp = fractions.gcd(tmp,l)
                           if i == j == l:
                                    ans += tmp
                           elif i == j or j == l or l == i:
                                    ans += 3 * tmp
                           else:
                                    ans += 6 * tmp
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 numpy as np


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


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

print(total)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

n = int(input())
s = 0
for a in range(1, n+1):
    for b in range(1, n+1):
        for c in range(1, n+1):
            s += gcd(*[a, b, c])
print(s)

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 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:
from fractions import gcd

N = int(input())

G = 0

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

print(G)

Submission status: Time Limit Exceeded

Solution code:
import math
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 += math.gcd(x,math.gcd(y,z))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import math
k= int(input())
ans = 0
dic = defaultdict(int)
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            if (a,b) not in dic:
                x = math.gcd(a,b)
                dic[(a,b)] = x
            x = dic[(a,b)]
            if (x,c) not in dic:
                x = math.gcd(x,c)
                dic[(x,c)] = x
            ans += dic[(x,c)]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd 
from functools import reduce
import itertools
k = int(input())
a = [i for i in range(1,k+1)]
s = 0
for t in itertools.product(a,repeat=3):
  s += reduce(gcd,t)
print(s)

Submission status: Time Limit Exceeded

Solution code:
n = 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)
  
c = 0
  
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:
K = int(input())

import fractions

A = []
sum = 0

for i in range(K):
    for j in range(K):
        A.append(fractions.gcd(i+1,j+1))

for g in A:
    for i in range(K):
        sum += fractions.gcd(g,i+1)

print(sum)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
mem = {}
def gcd(a, b):
    global mem
    if (a, b) not in mem:
        mem[(a, b)] = a if b == 0 else gcd(b, 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):
        for k in range(1, K+1):
            res += gcd(gcd(i, j), k)
print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math

k = int(input())

l = list(itertools.product(list(range(1, k+1)), repeat=3))
ans = 0

for i in l:
    a, b, c = i
    ans += math.gcd(math.gcd(a, b), c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
if __name__ == "__main__":
    # K>=200 なので3重ループは間に合わなそう
    K = int(input())
    gcd_dic = {}

    for i in range(1, K+1):
        for j in range(i, K+1):
            gcd_dic[(i,j)] = math.gcd(i, j)
    #print(gcd_dic)
    ans = 0
    for i in range(1, K+1):
        for j in range(1, K+1):
            ij_gcd = gcd_dic[(min(i, j), max(i,j))]
            #print(ij_gcd)
            for k in range(1, K+1):
                ans +=  gcd_dic[(min(ij_gcd, k), max(ij_gcd,k))]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

K=int(input())
ls = [i for i in range(1,K+1)]
ans=0
for i in range(1,K+1):
  for j in range(1,K+1):
    tempgcd=np.gcd(i, j)
    for k in range(1,K+1):
      ans += np.gcd(tempgcd, k)
      
print(ans)

Submission status: Time Limit Exceeded

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

def get_three_nums_gcd(i1,i2,i3):
    import math
    a = math.gcd(i1,i2)
    return math.gcd(a,i3)

for m in range(1,K+1):
    for n in range(1,K+1):
        for o in range(1,K+1):
            ans += get_three_nums_gcd(m,n,o)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin

d = dict()


def gcd(a, b):
    if (a, b) in d:
        return d[(a, b)]
    if b == 0:
        return a
    else:
        res = gcd(b, a % b)
        d[(a, b)] = res
        return res
    return


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


def main():
    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 += gcd_3(a, b, c)
    print(res)


def input(): return stdin.readline().rstrip()


main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import fractions


def tri_gcd(p, q, r):
    tmp_gcd = fractions.gcd(p, q)
    return fractions.gcd(tmp_gcd, r)


k = int(input())
res = 0
for a in range(1, k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            tk = tri_gcd(a, b, c)
            if (a == b) & (b == c):
                res += tk
            elif (a!=b) & (b!=c) & (c!=a):
                res += tk*6
            else:
                res += tk*3

print(res)

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import itertools as it

d = {}
def _gcd(a,b):
    a, b = max(a,b), min(a,b)
    while b:
        if d.get((a, b), False):
            return d[(a, b)]
        else:
            a, b = b, a%b

    d[(a, b)] = a
    return a

# def _gcd(a,b):
#     a, b = max(a,b), min(a,b)
#     if b == 0:
#         d[(a, b)] = a
#         return a
#     elif d.get((a, b), False):
#         return d[(a, b)]
#     else:
#         ans = _gcd(b, a%b)
#         d[(a, b)] = ans
#         return ans

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

def solve(K: int):
    ans = 0
    r = range(1, K+1)
    for (a,b,c) in it.product(r,r,r):
        ans += gcd(a,b,c)
    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
import math
i = 0
l = list(range(K+1))[1:]

for a in l:
    for b in l:
        for c in l:
            i += math.gcd(math.gcd(a,b), c)
print(i)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

ans = 0
#count = 0
for i in range(1, K + 1):
  for j in range(i, K + 1):
    for k in range(j, K + 1):
      #count += 1
      #print(count, gcd3(i, j, k))
      x = gcd3(i, j, k)
      if i == j:
        if j == k:
          ans += x
        else:
          ans += 3 * x
      else:
        if i == k:
          ans += 3 * x
        elif j == k:
          ans += 3 * x
        else:
          ans += 6 * x
          

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

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

print(_sum)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
k=int(input())
a=[0]*k
b=[0]*(k*k)
c=[0]*(k*k*k)
for i in range(k):
  a[i]=i+1
for i in range(k):
  for j in range(k):
    b[k*i+j]=gcd(a[i],j+1)
for i in range(k):
  for j in range(k):
    for l in range(k):
      c[k*k*i+k*j+l]=gcd(b[k*i+j],l+1)
print(sum(c))

Submission status: Time Limit Exceeded

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

n=K**3
ABC=[0]*3
ans=0
for i in range(n):
    for j in range(3):
        ABC[j]=i%K+1
        i//=K
    val=math.gcd(ABC[0],ABC[1])
    val=math.gcd(val,ABC[2])
    ans+=val
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)


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


if __name__ == "__main__":
    K = in_ctrl()
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 0
    # 全部同じ数字(a=b=c)
    for a in range(1,K+1):
        cnt += a
    # 1つ同じ数字(a<b=c)
    for a in range(1,K+1):
        for b in range(a+1,K+1):
            ans = fractions.gcd(a,b)
            cnt += 6*ans
    # 全部違う数字(a<b<c)
    for a in range(1,K+1):
        for b in range(a+1,K+1):
            for c in range(b+1,K+1):
                if a !=b and b!=c:
                    ans = fractions.gcd(a,b)
                    cnt += 6*fractions.gcd(ans, c)
                else:
                    pass
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    out_ctrl(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
# sys.stdin = open('input.txt')

from math import gcd


def triple_gcd(x, y, z):
    return gcd(gcd(x, y), z)


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 += triple_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)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def find_gcd(x, y):
	while(y): 
		x, y = y, x % y 
	
	return x 
		 
n = int(input())
gcd = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            x = find_gcd(i, j)
            gcd += find_gcd(x, k)
print(gcd)

Submission status: Time Limit Exceeded

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

num = int(input())
a_list = [i for i in range(1,num+1)]
b_list = a_list.copy()
c_list = a_list.copy()
comb_list = list(itertools.product(a_list,b_list,c_list))

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

sum_yaku = 0
for i in comb_list:
    num_list = list(i)
    sum_yaku += gcd_list(num_list)
print(sum_yaku)

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache

N = int(input())

@lru_cache(maxsize=None)
def gcd2(a, b):
  if b == 0:
    return a
  return gcd2(b, a % b)

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

res = 0

for i in range(1, N + 1):
  for j in range(1, N + 1):
    for k in range(1, N + 1):
      res += gcd(i, j, k)

print(res)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

k = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush, heapify
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
from functools import reduce
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm_base(a, b):
    return (a * b) // gcd(a, b)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def main():
  k = int(input())
  ans = 0
  for a in range(1, k+1):
    for b in range(a, k+1):
      for c in range(b,k+1):
        if a==b and b==c:
          ans += gcd(gcd(a,b),c)
        elif a==b or b==c or c==a:
          ans += gcd(gcd(a,b),c) * 3
        else:
          ans += gcd(gcd(a,b),c) * 6
  print(ans)
  
  
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
num=int(input())
sum1=0
def find_gcd(x, y): 
      
    while(y): 
        x, y = y, x % y 
      
    return x 
for i in range(1, num+1):
    for j in range(1, num+1):
        for k in range(1, num+1):
            sum1= sum1 + find_gcd(find_gcd(i,j),k)
print(sum1)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations_with_replacement
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10 ** 6)

def input():
    return sys.stdin.readline()[:-1]

def main():
    n = int(input())
    ans = 0
    for c in combinations_with_replacement(list(range(1, n+1)), 3):
        if c[0] == c[1] and c[1] == c[2]:
            ans += gcd(gcd(c[0], c[1]), c[2])
        elif c[0] != c[1] and c[1] != c[2]:
            ans += gcd(gcd(c[0], c[1]), c[2]) * 6
        else:
            ans += gcd(gcd(c[0], c[1]), c[2]) * 3
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

#最大公約数
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


k = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
k = int(input())
n = 0
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1,k+1):
      n += np.gcd.reduce([j, i, l])
print(n)

Submission status: Time Limit Exceeded

Solution code:
#x,y,z = list(map(int,input().split()))
# 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)

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


print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def kk(n,m):
    if n<m:
        n,m=m,n
    while  n%m!=0:
        n=n%m
        n,m=m,n
    return m


k= int(input())
count=0
for p in range(1,k+1):
    for q in range(1,k+1):
        pq=  kk(p,q)
        for r in range(1,k+1):
             pqr= kk(pq,r)
             count= count+ pqr
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

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

K=int(input())

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

temp_sum=0
for j in itertools.product(l, repeat=3):
    temp_sum+=gcd_list(list(j))

print(temp_sum)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

print(total)

Submission status: Time Limit Exceeded

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

permutations_lis = list(itertools.product(range(1,k+1), repeat=3))
for one_case in permutations_lis:
    ans += math.gcd(one_case[0],math.gcd(one_case[1],one_case[2]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
import itertools
k = int(input()) 
l = list(range(1, k + 1))
ans = 0
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
for v in itertools.product(l, repeat=3):
    ans += gcd(*list(v))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import fractions

k=int(input())
tot=0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

K = int(input())
total = 0

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

k = int(input())

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


print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import math
import fractions
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

k = I()

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

n = int(input())
def gcd(*numbers):
    return reduce(math.gcd, numbers)

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

print(c)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

from itertools import product
kumi = product(range(1, K+1), repeat=3)

from fractions import gcd

memo = [[None for i in range(K+1)] for i in range(K+1)]
# memo2 = {}

ans = 0
for a, b, c in kumi:
    a, b, c = sorted([a, b, c])
    if memo[a][b] is not None:
        v = memo[a][b]
    else:
        v = gcd(a, b)
        memo[a][b] = v
        memo[b][a] = v
    d = gcd(v, c)
    ans += d

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

k = int(input())

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

print(s)

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

k = int(input())

result = 0

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

print(result)