Problem:


Score : 300 points

Problem Statement

Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

Constraints

1 \leq K \leq 200

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print the value of \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Sample Input 1

2

Sample Output 1

9

\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)
+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)
=1+1+1+1+1+1+1+2=9

Thus, the answer is 9.

Sample Input 2

200

Sample Output 2

10813692



Sample input:
2


Sample output:
9

Submission status: Time Limit Exceeded

Solution code:
import fractions

K = int(input())
result = 0
sum = 0

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

print(sum)

Submission status: Time Limit Exceeded

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


#print(gcd(8, 20))
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):
            a = gcd(i, j)
            ans += gcd(a, k)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

k = int(input())
ans = 0

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
    
def solution(K):
    ans = 0
    for i in range(1,K+1):
        for j in range(1,K+1):
            for k in range(1,K+1):

                ans += euclid(euclid(i,j), euclid(j,k))
    
    print(ans)

solution(K)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
    
def solution(K):
    ans = 0
    for i in range(1,K+1):
        for j in range(1,K+1):
            for k in range(1,K+1):
                ans += euclid(euclid(i,j), euclid(j,k))
    print(ans)

solution(K)

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

print(sum)
# print(gcd(2,6))

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

print(sum)
# print(gcd(2,6))

Submission status: Time Limit Exceeded

Solution code:
import math
def gcd(n1, n2, n3):
	gcd1, gcd2 = math.gcd(n1, n2), math.gcd(n2, n3)
	return math.gcd(gcd1, gcd2)
	
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):
			if a == 1 or b == 1 or c == 1:
				sum += 1
			else:
				sum += gcd(a, b, c)
			
print (sum)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
add=0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            a=[i,j,k]
            a.sort(reverse=True)
            while a[1]>0:
                u=a[1]
                v=a[0]%a[1]
                a[0]=u
                a[1]=v
            A=max(a[0],a[2])
            B=min(a[0],a[2])
            while B>0:
                u=B
                v=A%B
                A=u
                B=v
            add +=A
           
print(add)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
num = int(input())
ans = 0
for i in range(1, num + 1):
    for j in range(1, num + 1):
        for k in range(1, num + 1):
            ans += math.gcd(math.gcd(i, j), k)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
 
def gcd(array):
  return reduce(math.gcd, array)
 
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([i,j,k])
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
ans=0
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd,numbers)
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:
import math
import functools 

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

print(sum)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
def gud(a,b):
  if a%b==0:
    return b
  else:
    return gud(b,a%b)
a=int(input())
ans=0
for i in range(a):
  for j in range(a):
    n=gud(i+1,j+1)
    for k in range(a):
      ans+=gud(n,k+1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gud(a,b):
  if a%b==0:
    return b
  else:
    return gud(b,a%b)
a=int(input())
ans=0
for i in range(a):
  for j in range(a):
    for k in range(a):
      n=gud(i+1,j+1)
      ans+=gud(n,k+1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import functools
import math

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


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


#N = list(map(int, input().split()))

K = int(input())
SUM = 0
for a in range(K):
    a += 1
    for b in range(K):
        b += 1
        for c in range(K):
            c += 1
            NUMS = [a,b,c]
            SUM += euclid(euclid(a,b),c)
            #print("{}, {}".format(NUMS,SUM))
print("{}".format(SUM))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k=int(input())

def euclid(a,b):
    x=max(a,b)
    y=min(a,b)
    while x%y != 0:
        r=x%y
        x=y
        y=r
    return y

def euclid3(a,b,c):
    return euclid(euclid(a,b),c)

ans=0
for x in range(1,k+1):
    for y in range(1,k+1):
        for z in range(1,k+1):
            ans+=euclid3(x,y,z)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
a=1;b=1;c=1;d=0
n=int(input());
for i1 in range(n):
	for i2 in range(n):
		for i3 in range(n):
			d+=reduce(math.gcd,(a,b,c))
			c+=1
		b+=1;c=1;i3=0
	a+=1;b=1;i2=0
print(d)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
import math  
from functools import reduce
ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            ans = ans + reduce(math.gcd,[a,b,c]) 
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
N=int(input())
total=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)
      total+=ans
      
      
print(total)

Submission status: Time Limit Exceeded

Solution code:
import math
N=int(input())
total=[]
candi=[]

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

Submission status: Time Limit Exceeded

Solution code:
import math
N=int(input())
total=[]
candi=[]

for i in range(1,N+1):
  for j in range(1,N+1):
    for k in range(1,N+1):
      l=math.gcd(i,j)
      ans=math.gcd(l,k)
      total.append(ans)
      

print(sum(total))

Submission status: Time Limit Exceeded

Solution code:
import math
N=int(input())
total=[]
candi=[]

for i in range(1,N+1):
  for j in range(1,N+1):
    for k in range(1,N+1):
      candi.append([i,j,k])
for l in candi:
  ans=l[0]
  for m in l[1:]:
    ans=math.gcd(ans,m)
  else:
    total.append(ans)
print(sum(total))

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(M, m):
	a = max(M, m)
	b = min(M, m)
	q = b
	r = a % b
	while r != 0:
		p = q
		q = r
		r = p % q
	return q
	
K = int(input())
count = 0
temp = []
for a in range(1, K+1):
	for b in range(1, a):
		temp.append(gcd(a, b))
for c in range(1, K+1):
	for j in range(len(temp)):
		count += gcd(c, temp[j]) * 2
	for k in range(1, K+1):
		count += gcd(c, k)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math

s = [i for i in range(1,int(input())+1)]
ans = 0 

for a in s:
    for b in s:
        for c in s:
            ans += math.gcd(math.gcd(a,b), c)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b,c):
  x=0
  y=min([a,b,c])
  for i in range(y):
    if y%(i+1)!=0:
      continue
    elif a%(y/(i+1))==0 and b%(y/(i+1))==0 and c%(y/(i+1))==0:
      x=y/(i+1)
      break
  return x

def sum(k):
  s=0
  for x in range(k):
    for y in range(k):
      for z in range(k):
        if x<y and y<z:
          s+=6*gcd(x+1,y+1,z+1)
        elif x==y and y==z:
          s+=gcd(x+1,y+1,z+1)
        elif (x==y and y<z) or (x<y and y==z):
          s+=3*gcd(x+1,y+1,z+1)
        else:
          continue
  return s
i=int(input())
o=sum(i)
print(int(o))

Submission status: Time Limit Exceeded

Solution code:
def gcd(M, m):
	q = m
	r = M % m
	while r != 0:
		p = q
		q = r
		r = p % q
	return q
	
K = int(input())
gcd_sum = 0
for a in range(1, K+1):
	for b in range(1, K+1):
		for c in range(1, K+1):
			ab = gcd(b,a)
			gcd_sum += gcd(c, ab)
print(gcd_sum)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b,c):
  x=0
  y=min([a,b,c])
  for i in range(y):
    if a%(y-i)==0 and b%(y-i)==0 and c%(y-i)==0:
      x=y-i
      break
  return x

def sum(k):
  s=0
  for x in range(k):
    for y in range(k):
      for z in range(k):
        s+=gcd(x+1,y+1,z+1)
  return s
i=int(input())
o=sum(i)
print(o)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
def pregcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        r = a%b
        a = b
        b = r
    return a
def gcd(a, b, c):
    d = pregcd(a, pregcd(b, c))
    return d

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

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b,c):
  x=0
  for i in range(min([a,b,c])):
    if a%(i+1)==0 and b%(i+1)==0 and c%(i+1)==0:
      x=i+1
  return x

def sum(k):
  s=0
  for x in range(k):
    for y in range(k):
      for z in range(k):
        s+=gcd(x+1,y+1,z+1)
  return s
i=int(input())
o=sum(i)
print(o)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        r = a%b
        a = b
        b = r
    return a
count = 0
temp = list()
for n in range(1, K+1):
    for m in range(1, K+1):
        temp.append(gcd(n, m))
for l in range(1, K+1):
    for j in range(len(temp)):
        p = gcd(l, temp[j])
        count += p
print(count)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
def gcd(a, b):
    c = 1
    for i in range(1, min([a+1, b+1]))[::-1]:
        if a%i==0 and b%i==0:
            c = i
            break
        else:
            continue
    return c

count = 0
temp = list()
for n in range(1, K+1):
    for m in range(1, K+1):
        temp.append(gcd(n, m))
for l in range(1, K+1):
    for j in range(len(temp)):
        p = gcd(l, temp[j])
        count += p
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math

s = [i for i in range(1,int(input())+1)]
ans = 0 

for a in s:
    for b in s:
        for c in s:
            ans += math.gcd(math.gcd(a,b), math.gcd(b,c))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def getgcd(a, b, c):
	ilist = [a, b, c]
	ilist.sort()
	#	print(ilist[0])
	#	print(ilist[1])
	#	print(ilist[2])
	gcd = 1
	for i in range(ilist[0], 1, -1):
		if ilist[0] % i == 0 and ilist[1] % i == 0 and ilist[2] % i == 0:
			ilist[0] = ilist[0] / i
			ilist[1] = ilist[1] / i
			ilist[2] = ilist[2] / i
			gcd = i * gcd

	return gcd


k = int(input())

isum = 0
for a in range(1, k + 1):
	for b in range(1, k + 1):
		for c in range(1, k + 1):
			isum = isum + getgcd(a, b, c)

# isum = getgcd(16,16,32)
print(isum)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
def gcd(a, b):
    c = 1
    for i in range(1, min([a+1, b+1])):
        if a%i==0 and b%i==0:
            c = i
    return c

count = 0
temp = list()
for n in range(1, K+1):
    for m in range(1, K+1):
        temp.append(gcd(n, m))
for l in range(1, K+1):
    for j in range(len(temp)):
        p = gcd(l, temp[j])
        count += p
print(count)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
def gcd(a, b):
    c = 1
    for i in range(1, min([a+1, b+1])):
        if a%i==0 and b%i==0:
            c = i
    return c

count = 0
for n in range(1, K+1):
    for m in range(1, K+1):
        for l in range(1, K+1):
            q = gcd(m, l)
            p = gcd(n, q)
            count += p
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from math import *

K = int(input())

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

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# 入力
K = int(input())

sum = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    comp_i = i
    comp_j = j
    if i < j:
      comp_i, comp_j = comp_j, comp_i
    r = comp_i % comp_j
    while r!=0:
      comp_i = comp_j
      comp_j = r
      r = comp_i % comp_j

    for m in range(1,K+1):
      comp_m = m
      comp_jj = comp_j
      if comp_m < comp_jj:
        comp_m, comp_jj = comp_jj, comp_m
      l = comp_m % comp_jj
      while l != 0:
        comp_m = comp_jj
        comp_jj = l
        l = comp_m % comp_jj
      sum = sum + comp_jj
      
print(sum)

Submission status: Time Limit Exceeded

Solution code:
# 入力
K = int(input())

sum = 0
count = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    comp_i = i
    comp_j = j
    if i < j:
      comp_i, comp_j = comp_j, comp_i
    r = comp_i % comp_j
    while r!=0:
      comp_i = comp_j
      comp_j = r
      r = comp_i % comp_j

    for m in range(1,K+1):
      comp_m = m
      comp_jj = comp_j
      if comp_m < comp_jj:
        comp_m, comp_jj = comp_jj, comp_m
      
      l = comp_m % comp_jj
      while l != 0:
        comp_m = comp_jj
        comp_jj = l
        l = comp_m % comp_jj
      sum = sum + comp_jj
      
print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(A)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
import math
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,k),j)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from functools import reduce


def main():
    input = sys.stdin.readline
    K = int(input())
    assert 1 <= K <= 200
    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_list([i, j, k])
    print(total)


def gcd_list(numbers):
    return reduce(euclidean_algorithm, numbers)


def euclidean_algorithm(a, b):
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b
    return b


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from functools import reduce


def main():
    input = sys.stdin.readline
    K = int(input())
    assert 1 <= K <= 200
    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_list([i, j, k])
    print(total)


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


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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
k = int(input())
ans = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for y in range(1, k+1):
            ans += gcd(gcd(i,j), y)
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=ans+gcd(i,j,k)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b):
    r0=a
    r1=b
    while True:
        r2=r0%r1
        if r2==0:break
        r0=r1
        r1=r2
    return(r1)

K=int(input())
tot=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):
            tot+=gcd(tmp,k)
            
print(tot)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def gcd(a, b, c):
    minV = min([a, b, c])
    maxV = max([a, b, c])
    start = minV
    diff = maxV - minV
    if diff < start and diff != 0:
        start = diff
    for gcdV in range(start, 1, -1):
        if (a % gcdV == 0) and (b % gcdV == 0) and (c % gcdV == 0):
            return gcdV
    return 1


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:
# In peace, in love, in war, everything is the same

import math

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

Submission status: Time Limit Exceeded

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

K = inputI()

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
def gcd3(a, b, c):
    return gcd(gcd(a, b), c)


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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
def gcd(p,q):
    temp=p%q
    while temp!=0:
        p=q
        q=temp
        temp=p%q
    return q
def gcd0(a,b,c):
    return gcd(gcd(a,b),c)

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

Submission status: Time Limit Exceeded

Solution code:
import math
N=int(input())
total=[]

for i in range(1,N+1):
  for j in range(1,N+1):
    for k in range(1,N+1):
      lis=[i,j,k]
      ans = lis[0]
      for l in range(1,3):
        ans = math.gcd(ans,lis[l])
      else:
        total.append(ans)
        
print(sum(total))

Submission status: Time Limit Exceeded

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

K = input()
K = int(K)
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
from functools import reduce

K = int(input())

gcd_sum = 0
target_range = range(1, K + 1)

for a in target_range:
  for b in target_range:
    for c in target_range:
      gcd_sum += reduce(math.gcd, (a, b, c))

print(gcd_sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())

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


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 sys import stdin
import sys
import math

K = int(input())

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

print(amount)

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

Submission status: Time Limit Exceeded

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

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

print(sum)

Submission status: Time Limit Exceeded

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

N = int(input())
result = [gcd(gcd(i,j),k) for i in range(1,N+1) for j in range(1,N+1) for k in range(1,N+1)]
print(sum(result))

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
    
N = int(input())
result = [gcd(gcd(i,j),k) for i in range(1,N+1) for j in range(1,N+1) for k in range(1,N+1)]
print(sum(result))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
result = [np.gcd(np.gcd(i,j),k) for i in range(1,N+1) for j in range(1,N+1) for k in range(1,N+1)]
print(sum(result))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
result=0
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            result += np.gcd(np.gcd(i,j),k)
print(result)

Submission status: Time Limit Exceeded

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

res = 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):
            res += gcd(t, c)

print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys
from fractions import gcd

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

K = int(read())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

# input
N = int(input())

# sub
ans = 0
for a in range(1, N + 1):
    for b in range(1, N + 1):
        for c in range(1, N + 1):
            if 1 in [a, b, c]:
                ans += 1
            elif a == b == c:
                ans += a
            else:
                ans += reduce(math.gcd, (a, b, c))

# output
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

# input
N = int(input())

# sub
ans = 0
for a in range(1, N + 1):
    for b in range(1, N + 1):
        for c in range(1, N + 1):
            ans += reduce(math.gcd, (a, b, c))

# output
print(ans)