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:
def gcd_2(a,b):
    if a<=b:
        x_min=a
        x_max=b
    else:
        x_min=b
        x_max=a
        
    while True:
#         print(x_min,x_max)
        if x_max % x_min ==0:
            return x_min
        
        x_temp = x_max % x_min
        
        x_max = x_min
        x_min = x_temp
        
def gcd(a,b,c):
    d=gcd_2(a,b)
    ans=gcd_2(d,c)
    return ans
  
N=int(input())
sum_gcd=0
for a_1 in range(1,N+1):
    for a_2 in range(1,N+1):
        for a_3 in range(1,N+1):
            sum_gcd+=gcd(a_1,a_2,a_3)
print(sum_gcd)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

if __name__== "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
import math

n=int(input())
 
total=0
for nn in range(1,n+1):
  for k in range(1,n+1):
    for l in range(1,n+1):
      total+=math.gcd(nn,math.gcd(k,l))
 
print(total)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
def gcd(a, b):
    while b != 0:
        r = a%b
        a = b
        b = r
    return a
gcds = [gcd(gcd(a,b),c) for a in range(1, K+1) for b in range(1, K+1) for c in range(1, K+1)]
print(sum(gcds))

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
a = int(input())
result = 0
# target_list = []
for x in range(1, a+1):
    for y in range(1, a+1):
        for z in range(1, a+1):
            result += reduce(math.gcd, (x, y, z))
            # target_list.append((x, y, z))

# for target in target_list:
    # result += reduce(math.gcd, target)
print(result)

Submission status: Time Limit Exceeded

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

target_list = []
for x in range(1, a+1):
    for y in range(1, a+1):
        for z in range(1, a+1):
            target_list.append((x, y, z))
result = 0
for target in target_list:
    result += reduce(math.gcd, target)
print(result)

Submission status: Time Limit Exceeded

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


a = int(input())
sum = 0
for aum in range(1,a+1):
  for bum in range(1,a+1):
    for cum in range(1,a+1):
      sum += gcd(aum,bum,cum)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
sum = 0

for i in range(N):
    for j in range(N):
        for k in range(N):
            g = math.gcd(i+1,j+1)
            sum += math.gcd(g,k+1)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

a=int(input())
ans=0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())


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


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

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

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
y = 0

for i in range(n):
  for j in range(n):
    for k in range(n):
      y_ = math.gcd(math.gcd(i+1, j+1), k+1)
      y += y_
 
print(y)

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
y = 0

for i in range(n):
  for j in range(n):
    for k in range(n):
      i_ = i + 1
      j_ = j + 1
      k_ = k + 1
      y_ = math.gcd(math.gcd(i_, j_), k_)
      y += y_
 
print(y)

Submission status: Time Limit Exceeded

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

def gcd(x, y):
  if x % y == 0:
    return y
  return int(gcd(y, x%y))

for i in range(n):
  for j in range(n):
    for k in range(n):
      i_ = i + 1
      j_ = j + 1
      k_ = k + 1
      y_ = gcd(gcd(i_, j_), k_)
      y += y_
 
print(y)

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)

num=int(input())


sum=0
for n in range(1,num+1):
    for m in range(1,num+1):
        for l in range(1,num+1):
            sum=sum+gcd(n,m,l)
            
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import io


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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b):
    c = 0
    if b > a:
        a,b = b,a
    while a % b != 0:
        c = b
        b = a % b
        a = c
    return b
def gcd3(a,b,c):
    return gcd(gcd(a,b),c)
K = int(input())
count = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            count += gcd3(i,j,k)
print(count)

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

Submission status: Time Limit Exceeded

Solution code:
# C
k = int(input())

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

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:
import math

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

Submission status: Time Limit Exceeded

Solution code:

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np

def gcd3(a, b, c):
    if a == 1 or b == 1 or c == 1:
        return 1
    else:
        return math.gcd(math.gcd(a, b), c)

def sum_of_gcd(K):
    con = 0
    K_list = np.arange(K) + 1
    for a in K_list:
        for b in K_list:
            for c in K_list:
                con += gcd3(a, b, c)

    return con


K = input()
print(sum_of_gcd(int(K)))

Submission status: Time Limit Exceeded

Solution code:

from math import gcd
import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)

K = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
 
K = int(input())
 
lis = tuple([i for i in range(1,K+1)])
a = 0
sel = set([])
mydict = {}
inse = set([])
for i in lis:
    for j in lis:
        for k in lis:
            inse = set([i,j,k])
            if str(inse) in mydict.keys() == True:
                a += mydict[str(inse)]
            else:
                gcd_a = gcd(gcd(i,j),k)
                mydict[str(inse)] =gcd_a
                a += gcd_a
        
print(a)

Submission status: Time Limit Exceeded

Solution code:

#from math import gcd
import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)

K = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
def gcd_two(a,b):
  if a < b:
    a,b=b,a
  while a % b != 0:
      a, b = b, a % b
  return b

def gcd_three(a,b,c):
  ans = gcd_two(a,b)
  ans = gcd_two(ans,c)
  return ans
  
sum_gcd = 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 += gcd_three(i,j,k)
print(sum_gcd)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(N)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())
valSum = 0

for A in range(1,K+1):
    for B in range(1,K+1):
        for C in range(1,K+1):
            valSum += math.gcd(math.gcd(A,B),C)

print(valSum)

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

Submission status: Time Limit Exceeded

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

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

for A in range(1,K+1):
    for B in range(1,K+1):
        for C in range(1,K+1):
            valSum = origcd(origcd(A,B),C) + valSum

print(valSum)

Submission status: Time Limit Exceeded

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

for a in range(1,K+1):
    for b in range(a,K+1):
        for c in range(b,K+1):
            g = gcd(a,b)
            g = gcd(g,c)
            if(a != 1 or b != 1 or c != 1 ):
                if(a != b or a != c):
                    if(a != K or b != K or c != K ):
                        if(a != b and a != c and b != c):
                            g *= 6
                        else:
                            g *= 3
            N += g

print(N)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())
valSum = 0

for A in range(1,K+1):
    for B in range(1,K+1):
        for C in range(1,K+1):
            valSum = math.gcd(math.gcd(A,B),C) + valSum

print(valSum)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())
N = 0

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

print(N)

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:
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

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

Submission status: Time Limit Exceeded

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

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

print(gcd)

Submission status: Time Limit Exceeded

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

print(gcd)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input());
gcd = 0;
gcd1 = 0;

for a in range(K):
  aa = a + 1 ;
  
  for b in range(K):
    bb = b + 1;
    
    for c in range(K):
      cc = c + 1;
      gcd1 = math.gcd(aa,bb);
      gcd += math.gcd(gcd1,cc);
      
print(gcd)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input());
gcd = 0;
gcd1 = 0;
gcd2 = 0;

for a in range(K):
  aa = a + 1 ;
  
  for b in range(K):
    bb = b + 1;
    
    for c in range(K):
      cc = c + 1;
      gcd1 = math.gcd(aa,bb);
      gcd2 = math.gcd(bb,cc);
      gcd += math.gcd(gcd1,gcd2);
      
print(gcd)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

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

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

print(ans)

Submission status: Time Limit Exceeded

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

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys

n = int(input())
ret = 0
for i in range(1, n + 1):
    for j in range(1, n + 1):
        for k in range(1, n + 1):
            gcd = 1
            for l in range(2, max(i, j, k) + 1):
                if i % l == 0 and j % l == 0 and k % l == 0:
                    gcd = l
            ret += gcd
print(ret)

Submission status: Time Limit Exceeded

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import math

    
def main():
	num = int(input())
	sum = 0
	for i in range(num):
		a = i+1
		for j in range(num):
			b = j+1
			for k in range(num):
				c = k+1
				if a == b:
					sum += math.gcd(a,c)
				elif b == c or a == c:
					sum += math.gcd(a,b)
				else:
					sum += math.gcd(math.gcd(a,b),c)
	print (sum)

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
    
def main():
	num = int(input())
	sum = 0
	for i in range(num):
		a = i+1
		for j in range(num):
			b = j+1
			for k in range(num):
				c = k+1
				if a == b:
					sum += math.gcd(a,c)
				elif b == c or a == c:
					sum += math.gcd(a,b)
				else:
					sum += gcd(a,b,c)
	print (sum)

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import math
from functools import reduce

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

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
import itertools
def GCD(a,b):
    if(a%b == 0):
        return b
    else:
        return GCD(b,a%b)
total = 0
for i in list(itertools.product(list(range(1,k+1)), repeat = 3)):
    a = int(i[0])
    b = int(i[1])
    c = int(i[2])
    total += GCD(GCD(a,b),c)
print(total)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

def gcd(numbers):
    return reduce(fractions.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 fractions
from functools import reduce

def gcd(numbers):
    return reduce(fractions.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:
# -*- coding: utf-8 -*-
import math

n = int(input())+1
a = int(0)
for i in range(1, n):
  for j in range(1, n):
    for k in range(1, n):
      a = a + math.gcd(i,math.gcd(j,k))
print("{}".format(a))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
import itertools
def GCD(a,b):
    mx = max(a,b)
    mi = min(a,b)
    if(mx%mi == 0):
        return mi
    else:
        return GCD(mi,mx%mi)
total = 0
for i in list(itertools.product(list(range(1,k+1)),repeat=3)):
    a = int(i[0])
    b = int(i[1])
    c = int(i[2])
    #print(a,b,c)
    total += GCD(GCD(a,b),c)
print(total)

Submission status: Time Limit Exceeded

Solution code:
a = int(input());
c = 0;
def gcd(a,b):
    if(b==0):
        return a
    else:
        return gcd(b,a%b)
for i in range(1,a+1):
    for j in range(1,a+1):
        for t in range(1,a+1):
            c += gcd(i,gcd(j,t));
print(c);

Submission status: Time Limit Exceeded

Solution code:
a = int(input());
c = 0;
def gcd(a,b):
    if(b==0):
        return a
    else:
        return gcd(b,a%b)
def gcds(x, y, z):
    return gcd(x, gcd(y,z));
for i in range(1,a+1):
    for j in range(1,a+1):
        for t in range(1,a+1):
            c += gcds(i,j,t);
print(c);

Submission status: Time Limit Exceeded

Solution code:
a = int(input());
c = 0;
def gcd(x,y):
    while (y):
        x, y = y, x % y
    return x
def gcds(x, y, z):
    return gcd (x, gcd(y,z));
for i in range(1,a+1):
    for j in range(1,a+1):
        for t in range(1,a+1):
            c += gcds(i,j,t);
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
# import numpy as np
from fractions import gcd
 
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10 ** -7
 
def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))
 
def lcm(x, y): return (x * y) // gcd(x, y)
 
 
def gcd_3(x, y, z):
    return gcd(gcd(x, y), z)
 
K = inp()
 
# dic = {} # key: (i, j, k), el: gcd(i, j, k)
ans = 0
for i in range(1, K + 1):
    for j in range(i, K + 1):
        for k in range(j, K + 1):
            a = gcd_3(i, j, k)
            if i == j == k:
                ans += a
            elif i == j or j == k:
                ans += a * 3
            else:
                ans += a * 3 * 2
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()) + 1
ans = 0
for x in range(1, N):
    for y in range(1, N):
        for z in range(1, N):
            ans += gcd(x, y, z)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math


K = int(input())

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
K = [i for i in range(1, int(input()) + 1)]
numbers = itertools.product(K, repeat=3)

sum_gcd = 0
for i in numbers:
    a = math.gcd(i[0], i[1])
    b = math.gcd(a, i[2])
    sum_gcd += b

print(sum_gcd)

Submission status: Time Limit Exceeded

Solution code:
import math

n=int(input())
total=0

for i in range(n):
  for j in range(n):
    for k in range(n):
      gcdij=math.gcd(i+1,j+1)
      gcd=math.gcd(gcdij,k+1)
      total+=gcd
      
print(total)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

total=0

for i in range(n):
  #print(f'i+1={i+1}')
  j=i
  while j<n:
    #print(f'j+1={j+1}')
    k=j
    while k<n:
      #print(f'k+1={k+1}')
      kouho=min(i+1,j+1,k+1)
      while True:
        #kouhoが最大公約数の時
        if (i+1)%kouho==0 and (j+1)%kouho==0 and (k+1)%kouho==0:
          #３つとも同じ数字
          if i==j and j==k:
            total+=kouho
          #２つのみ同じ数字
          elif i==j or j==k or k==i:
            total+=kouho*3
          #同じ数字がない時
          else:
            total+=kouho*6
          break
        else:
          kouho -= 1
      k+=1
    j+=1
          
print(total)

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

import numpy as np 

# Input Stdin
## 1 <= K <= 200

K = int(input())

def gcd(p, q):
    while(q!=0):
        r = p % q
        p = q
        q = r
    return(p)

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

print(sum_gcd)

Submission status: Time Limit Exceeded

Solution code:
import fractions

K = int(input())
g = 0
for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            a = fractions.gcd(i, j)
            b = fractions.gcd(a, k)
            if i != j != k:
                g += b*6
            elif i == j == k:
                g += b
            else:
                g += b*3


print(g)

Submission status: Time Limit Exceeded

Solution code:
import fractions

K = int(input())
g = []
for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            a = fractions.gcd(i, j)
            b = fractions.gcd(a, k)
            if i != j != k:
                g.append(b)
                g.append(b)
                g.append(b)
                g.append(b)
                g.append(b)
                g.append(b)
            elif i == j == k:
                g.append(b)
            else:
                g.append(b)
                g.append(b)
                g.append(b)

print(sum(g))

Submission status: Time Limit Exceeded

Solution code:
import itertools
import fractions

K = int(input())
K = [i for i in range(1, K+1)]
p = itertools.combinations_with_replacement(K, 3)
p = list(p)
g = []

for i in p:
    a = fractions.gcd(i[0], i[1])
    b = fractions.gcd(a, i[2])
    if i[0] != i[1] != i[2]:
        g.append(b)
        g.append(b)
        g.append(b)
        g.append(b)
        g.append(b)
        g.append(b)
    elif i[0] == i[1] == i[2]:
        g.append(b)
    else:
        g.append(b)
        g.append(b)
        g.append(b)


print(sum(g))

Submission status: Time Limit Exceeded

Solution code:
import math
k=int(input())
a=1
s=0
while a<=k:
  b=1
  while b<=k:
    c=1
    while c<=k:
      g=math.gcd(a,b)
      s+=math.gcd(g,c)
      c+=1
    b+=1
  a+=1
print(s)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import fractions

K = int(input())
K = [i for i in range(1, K+1)]
p = itertools.product(K, repeat=3)
p = list(p)

g = []

for i in p:
    a = fractions.gcd(i[0], i[1])
    b = fractions.gcd(a, i[2])
    g.append(b)

print(sum(g))

Submission status: Time Limit Exceeded

Solution code:
import itertools
import fractions

K = int(input())
K = [i for i in range(1, K+1)]
p = itertools.product(K, repeat=3)
p = list(p)

g = []

for i in p:
    g.append(fractions.gcd(i[0], i[1]))

for i in range(len(g)):
    g[i] = fractions.gcd(g[i], p[i][2])

print(sum(g))

Submission status: Time Limit Exceeded

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

import numpy as np 

# Input Stdin
## 1 <= K <= 200

K = int(input())

sum_gcd = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            sum_gcd = sum_gcd + np.gcd.reduce(np.array([a, b, c]))

print(sum_gcd)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
from functools import reduce


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

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

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

Submission status: Time Limit Exceeded

Solution code:
def gdc(x,y):
  if x%y==0:
    return y
  return gdc(y, x%y)

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

  for a in range(K):
    for b in range(K):
      for c in range(K):
        total += gdc(c+1, gdc(b+1, a+1))
  print(total)
  
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

def gdc(x,y):
  if x%y==0:
    return y
  return gdc(y, x%y)

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

k = int(input())
l = [[[0] * (k + 1) for i in range(k + 1)] for j in range(k + 1)]
ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            mn, mx = min(a, b, c), max(a, b, c)
            mi = a + b + c - mn - mx
            if l[a][b][c]:
                ans += l[a][b][c]
                continue
            else:
                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())
summary=0

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

print(summary)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

sum = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

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

print(s)

Submission status: Time Limit Exceeded

Solution code:
def gcd(x,y,z):
    for i in range(x, 0, -1):
        if x%i==0 and y%i==0 and z%i==0:
            #print(i)
            return i
            break
            
    

def main():
    import sys
    N = int(sys.stdin.readline())
    total=0
    for i in range(1, N+1):
        for j in range(i, N+1):
            for k in range(j, N+1):
                if i==j and j==k:
                    total +=gcd(i, j, k)
                elif i==j or j==k or i==k:
                    total +=gcd(i, j, k)*3
                else:
                    total +=gcd(i, j, k)*6
                
    print(total)
    


if __name__=='__main__':
    main()

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    import fractions as f
    N = int(sys.stdin.readline())
    total=0
    for i in range(1, N+1):
        for j in range(i, N+1):
            for k in range(j, N+1):
                if i==j and j==k:
                    total+=f.gcd(f.gcd(i,j), f.gcd(j,k))
                elif i==j or j==k or i==k:
                    total+=f.gcd(f.gcd(i,j), f.gcd(j,k))*3
                else:
                    total+=f.gcd(f.gcd(i,j), f.gcd(j,k))*6
    print(total)
    


if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    import fractions as f
    N = int(sys.stdin.readline())
    total=0
    for i in range(1, N+1):
        for j in range(1, N+1):
            for k in range(1, N+1):
                total+=f.gcd(f.gcd(i,j), f.gcd(j,k))
    print(total)
    


if __name__=='__main__':
    main()