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

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
 
def gcd(x, y):
  if y == 0: return x
  else: return gcd(y, x % y)

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

Submission status: Time Limit Exceeded

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

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

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

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

GCD_table = [[-1] * (K + 1) for i in [1] * (K + 1)]
#print(GCD_table)

def GCD(a: int, b: int) -> int:
    if a <= b:
        return GCD_Recursive(b, a)
    else:
        return GCD_Recursive(a, b)

def GCD_Recursive(a: int, b: int) -> int:
    if GCD_table[a][b] != -1:
        return GCD_table[a][b]

    remain = a % b
    if remain == 0:
        # print("before:", GCD_table)
        # print("a", a)
        # print("b", b)
        GCD_table[a][b] = b
        GCD_table[b][a] = b
        # print("rewrite!")
        # print("after:", GCD_table)
        return b
    else:
        # GCD_table[a][b] = GCD_Recursive(b, remain)
        # GCD_table[b][a] = GCD_Recursive(b, remain)
        if GCD_table[b][remain] != -1:
            GCD_table[a][b] = GCD_table[b][remain]
            GCD_table[b][a] = GCD_table[b][remain]
            return GCD_table[b][remain]
        else:
            return GCD(b, remain)
ans = 0

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

# print(GCD_table)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

GCD_table = [[-1] * (K + 1) for i in [1] * (K + 1)]
#print(GCD_table)

def GCD(a: int, b: int) -> int:
    if a <= b:
        return GCD_Recursive(b, a)
    else:
        return GCD_Recursive(a, b)

def GCD_Recursive(a: int, b: int) -> int:
    if GCD_table[a][b] != -1:
        return GCD_table[a][b]

    remain = a % b
    if remain == 0:
        # print("before:", GCD_table)
        # print("a", a)
        # print("b", b)
        GCD_table[a][b] = b
        GCD_table[b][a] = b
        # print("rewrite!")
        # print("after:", GCD_table)
        return b
    else:
        GCD_table[a][b] = GCD_Recursive(b, remain)
        GCD_table[b][a] = GCD_Recursive(b, remain)
        return GCD_Recursive(b, remain)
ans = 0

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

# print(GCD_table)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

GCD_table = [[-1] * (K + 1) for i in [1] * (K + 1)]
#print(GCD_table)

def GCD(a: int, b: int) -> int:
    if a <= b:
        return GCD_Recursive(b, a)
    else:
        return GCD_Recursive(a, b)

def GCD_Recursive(a: int, b: int) -> int:
    if GCD_table[a][b] != -1:
        return GCD_table[a][b]

    remain = a % b
    if remain == 0:
        # print("before:", GCD_table)
        # print("a", a)
        # print("b", b)
        GCD_table[a][b] = b
        # print("rewrite!")
        # print("after:", GCD_table)
        return b
    else:
        return GCD_Recursive(b, remain)
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(GCD_table)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

Submission status: Time Limit Exceeded

Solution code:

from math import gcd#
# lst.reverse()
# type(s) returns the type of the object s .
def reverse(obj): return obj[::-1]
def p(obj): print(obj)


t = int(input())
sum = 0
for i in range(1, t+1):
    for j in range(1, t+1):
        for k in range(1, t+1):
            t1 = gcd(i, j)
            t2 = gcd(t1, k)
            sum += t2

print(sum)

Submission status: Time Limit Exceeded

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

num = 0

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

print(num)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a, b, c):
  import fractions
  lis = [a, b, c]
  gc = lis[0]
  for i in range(0, 3):
      gc = fractions.gcd(gc, lis[i])
  return gc
def main():
  K = int(input())
  ans = 0
  for p in range(1, K+1):
    for s in range(p, K+1):
      for k in range(s, K+1):
        if p == s == k:
          ans += p
        elif p == s or s == k or p == k:
          ans += 3 * gcd(p, s, k)
        else:
          ans += 6 * gcd(p, s, k)
  print(ans)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
import itertools


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


n = int(input())
ans = 0
A = list(range(1, n + 1))
for numbers in itertools.product(A, repeat=3):
    ans += gcd(gcd(numbers[0], numbers[1]), numbers[2])

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)


n = int(input())
ans = 0
A = list(range(1, n + 1))
for numbers in itertools.product(A, repeat=3):
    ans += gcd(numbers[0], numbers[1], numbers[2])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

k = int(input())

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

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

print(ans)

Submission status: Time Limit Exceeded

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

def main():
    resp = 0
    k = int(input())
    for i in range(1, k + 1):
        for j in range(1, k + 1):
            for w in range(1, k + 1):
                resp += mdc(mdc(i, j), w)

    print(resp)
                
    
main()

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools

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

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
def gcd(x,y,z):
    xy = math.gcd(x,y)
    xyz = math.gcd(xy,z)
    return xyz
k1 = int(input())
k = list(range(1,k1+1))*3
l = []
for i in itertools.combinations(k,3):
    l.append(i)
l = list(set(l))
num = 0
for h in l:
    t = gcd(h[0],h[1],h[2])
    num += t
print(num)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
from collections import Counter

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

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

n = int(input())
ans = ["-".join([str(i+1), str(j+1), str(k+1)])  for i in range(n) for j in range(n) for k in range(n)]
counts = Counter(ans)
ans = [gcd(int(k.split("-")[0]), int(k.split("-")[1]), int(k.split("-")[2])) * v for k, v in counts.items()]
print(sum(ans))

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(1,k+1):
        an=fractions.gcd(i,j)
        for s in range(1,k+1):
            anse=fractions.gcd(s,an)
            ans+=anse
print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
ans = []
max3 = 0
for i in range(1, k+1, 1):
    for j in range(1, k+1, 1):
        for l in range(1, k+1, 1):
            max3 = max([i, j, l])
            
            for m in range(min([max3, 100]), 0, -1):
                if i%m ==0 and j%m==0 and l%m ==0:
                    ans.append(m)
                    break
slist = sum(int(i) for i in ans)
print(slist)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
ans = []
max3 = 0
for i in range(1, k+1, 1):
    for j in range(1, k+1, 1):
        for l in range(1, k+1, 1):
            max3 = max([i, j, l])
            for m in range(max3, 0, -1):
                if i%m ==0 and j%m==0 and l%m ==0:
                    ans.append(m)
                    break
slist = sum(int(i) for i in ans)
print(slist)

Submission status: Time Limit Exceeded

Solution code:
#ARC162 C:Sum of gcd of Tuples(Easy)
import math
k = int(input())
ans = 0

if k == 1:
    ans = 1
else:
    for i in range(1,k+1):
        for j in range(1,k+1):
            for k in range(1,k+1):
                a = math.gcd(i,j)
                b = math.gcd(a,k)
                ans += b
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

k = int(input())

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())
ans = 0
for l in range(1,k+1):
  for m in range(1,k+1):
    for n in range(1,k+1):
      ans += math.gcd(math.gcd(l,m),n)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

# N = 200 x 200 x 200 = 8000000でO(N)で計算できることから間に合うはず
import math
ans = 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):
            ans += math.gcd(i,math.gcd(j,k))
print(ans)

Submission status: Time Limit Exceeded

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

k = int(input())
ans = 0
for l in range(1,k+1):
  for m in range(1,k+1):
    for n in range(1,k+1):
      ans += gcd(l,m,n)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
from itertools import product


K = int(input())
l = product(range(1, K+1), repeat=3)

ans = 0
for a, b, c in l:
    ans += gcd(gcd(a, b), c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K = int(input())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

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
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:
# coding: utf-8
import itertools
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
    
def main():
    k = int(input())
    ans = 0
    for a, b, c in itertools.product(range(1, k+1), range(1, k+1), range(1, k+1)):
        ans += gcd(a, b, c)
    print(ans)
    
main()

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
  
x = int(input())
num = 0
for i in range(1,x+1):
  for j in range(1,x+1):
    for k in range(1,x+1):
      num += gcd(i,j,k)
print(num)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:

def gcd_tri(a,b,c):
    if a < b:
        a,b = b,a
    while a % b != 0:
        a,b = b, a%b
    if b < c:
        b,c = c,b
    while b % c != 0:
        b,c = c, b%c
    return c

a = int(input())

ans =0
for n in range(a):
    for l in range(a):
        for m in range(a):
            ans += gcd_tri(n+1,l+1,m+1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

a = int(input())
def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans =0
for n in range(a):
    for l in range(a):
        for m in range(a):
            ans += gcd(n+1,l+1,m+1)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
k = int(input())
su = 0
for x in range(1, k+1):
  for y in range(1, k+1):
    for z in range(1, k+1):
      lis = [x, y, z]
      ans = x
      for p in range(1,3):
        ans = math.gcd(ans, lis[p])
      su += ans
      
print(su)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import math

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

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

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())
a=[]
for i in range(1,k+1):
  for j in range(1,k+1):
    for k in range(1,k+1):
      a.append(math.gcd(math.gcd(i,j),k))
print(sum(a))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

def gcd(a,b):
    mod = max(a,b) % min(a,b)
    if mod == 0:
        temp = min(a,b)
        return temp
    if a >= b:
        a = mod
    else:
        b = mod
    return gcd(a, b)

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

print(ans)

Submission status: Time Limit Exceeded

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

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

k = int(input())
ans = 0

n = list(product([i for i in range(1,k+1)],repeat=3))

for a,b,c in n:
    ans += gcd(a,b,c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
k = int(input())
ans = 0
for q in range(1,k+1):
    for r in range(1,k+1):
        for s in range(1,k+1):
            ans += math.gcd(q,math.gcd(r,s))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
def gcd(x,y,z):
    w = math.gcd(x,y)
    return math.gcd(w,z)
       
ans = 0            
for i in range(1,N+1) :
    for j in range(1,N+1):
        for k in range(1,N+1):
            s = gcd(i,j,k)
            ans += s
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

def gcd(x,y,z):
    x_list = []
    y_list = []
    z_list = []
 
    for i in range(1,x+1):
        if x % i == 0:
            x_list.append(i)     
        for j in x_list:
            if y % j == 0:   
                y_list.append(j)   
            for k in y_list:
                if z % k == 0:      
                    z_list.append(k)         
    return z_list[-1]  
       
ans = 0            
for i in range(1,N+1) :
    for j in range(1,N+1):
        for k in range(1,N+1):
            s = gcd(i,j,k)
            ans += s
print(ans)

Submission status: Time Limit Exceeded

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

import math

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

sum = 0
K = int(input())

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

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy
import math

K = int(input())

sum=0
for i in range(1, K+1):
    for j in range(1, K+1):
        for l in range(1, K+1):
            temp= math.gcd(i,j)
            sum += math.gcd(temp, l)


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(x,y):
  while (y):
    x, y = y, x%y
  return x

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

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

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
def gcd(p,q):
    if p%q==0:
        return q
    return gcd(q,p%q)
S=0
for i in range(K):
    for j in range(K):
        for k in range(K):
            S+=gcd(i+1,gcd(j+1,k+1))
print(S)

Submission status: Time Limit Exceeded

Solution code:
r=range(1,int(input())+1)
import math
from functools import reduce
def g(*n):return reduce(math.gcd, n)
print(sum(g(a,b,c) for a in r for b in r for c in r))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# import itertools
import math
# import sys
# import numpy as np

K = int(input())
# S = input()
# n, *a = map(int, open(0))
# K, N = map(int, input().split())
# A = list(map(int, input().split()))
# Q = list(map(int, input().split()))
# S = input()

# d = sorted(d.items(), key=lambda x:x[0]) # keyでsort

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

print(tot)

Submission status: Time Limit Exceeded

Solution code:
import math

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

Submission status: Time Limit Exceeded

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

K = int(input())

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
import functools

K = int(input())

ans = 0

for i in itertools.product(range(1,K+1),repeat=3):
    ans += functools.reduce(math.gcd,i)

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

Submission status: Time Limit Exceeded

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


def main():
    k = int(input())
    sumGCD = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                sumGCD += gcd(a, b, c)
    print(sumGCD)


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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
k = int(input())
#memo = [[0] * (k+1)] * (k+1)
#print(memo)
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:
from math import gcd
k = int(input())
sum = 0
for a in range(k):
    for b in range(k):
        for c in range(k):
            sum += gcd(gcd(a + 1, b + 1), c + 1)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

sum = 0

def gcd(x, y): # ユークリッドの互除法
    if y > x:
        y,x = x,y
    while y > 0:
        r = x%y
        x = y
        y = r
    return x

import math

for i in range(1,k+1):
    for m in range(1,k+1):
        for l in range(1,k+1):
            sum += math.gcd(math.gcd(i,m),l)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

sum = 0

def gcd(x, y): # ユークリッドの互除法
    if y > x:
        y,x = x,y
    while y > 0:
        r = x%y
        x = y
        y = r
    return x

for i in range(1,k+1):
    for m in range(1,k+1):
        for l in range(1,k+1):
            sum += gcd(gcd(i,m),l)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
from functools import reduce

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

N = int(input())
List1 = []
for i in range(1,N+1):
  List1.append(i)
x = itertools.product(List1,List1,List1)
tryList= list(x)
res = 0

for i in tryList:
  res += gcd_list(i)
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())
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:
def calc(a, b):
    m = min(a, b)
    l = max(a, b)
    while m != 0:
        s = m
        m = l % m
        l = s
    return l

K = int(input())
ans = 0
for i in range(K):
    for j in range(K):
        for k in range(K):
            if i == j == k:
                ans += i+1
            else:
                ans += calc(calc(i+1, j+1), k+1)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def calc(a, b):
    m = min(a, b)
    l = max(a, b)
    while m != 0:
        s = m
        m = l % m
        l = s
    return l

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
from functools import reduce
from math import gcd

n = int(sys.stdin.read())
print(sum(reduce(gcd, abc) for abc in itertools.product(range(1, n + 1), repeat=3)))

Submission status: Time Limit Exceeded

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
import functools
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
k = inp()
ans = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans += functools.reduce(euclid,[a,b,c])

print(ans)

Submission status: Time Limit Exceeded

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

l1 = [i for i in range(1, int(input()) + 1)]
print(sum(reduce(gcd, l) for l in product(l1, repeat=3)))

Submission status: Time Limit Exceeded

Solution code:
import math
#from functools import reduce

k = int(input())

lis = [(0)] * (250*250)
ans = 0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      x = math.gcd(b,c)
      lis[b + (250*c)] = (x)
      ans += lis[a + (250*x)]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

K = int(input())

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

ans = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      ans += gcd(i,j,k)
      # print(f'i,j,k:{i},{j},{k}, ans:{gcd(i,j,k)}')
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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