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())
ans = 0


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


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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from functools import reduce

n = int(input())
sum = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

n = int(input())
sum = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
# ABC 162

# https://note.nkmk.me/python-gcd-lcm/
A = int(input())
# 最小公倍数
ans = 0
from fractions import gcd
from functools import reduce

def Ngcd(*numbers):
    return reduce(gcd, numbers)
d = dict()

for i in range(1,A+1):
    for j in range(1,A+1):
        for k in range(1,A+1):
            tmp = ','.join(list(map(str,sorted([i,j,k]))))
            if tmp in d.keys():
                ans +=d[tmp]
            else:
                min_bai = Ngcd(i,j,k)
                d[tmp] = min_bai
                ans += min_bai
print(ans)

Submission status: Time Limit Exceeded

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

ll = []
for i in range(1, k + 1):
    l = []
    for j in range(1, i + 1):
        if i % j == 0:
            l.append(j)
            l.append(i // j)
        if (i // j) < j:
            break
    ll.append(set(l))


sum_k = 0

for i in range(k):
    for j in range(k):
        for l in range(k):
            sum_k += max(ll[i] & ll[j] & ll[l])

print(sum_k)

Submission status: Time Limit Exceeded

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    k = I()
    r = 0
    for a,b,c in itertools.combinations_with_replacement(range(1,k+1), 3):
        g = fractions.gcd(fractions.gcd(a,b), c)
        if a == b:
            if b == c:
                r += g
            else:
                r += g * 3
        elif b == c:
            r += g * 3
        else:
            r += g * 6

    return r


print(main())

Submission status: Time Limit Exceeded

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    k = I()
    r = k * k
    for a in range(2, k+1):
        for b in range(1, k+1):
            g = fractions.gcd(a, b)
            if g == 1:
                r += k
                continue
            for c in range(1, k+1):
                r += fractions.gcd(g, c)

    return r


print(main())

Submission status: Time Limit Exceeded

Solution code:
def gcd(p,q):
  if p % q == 0:
    return q
  return gcd(q, p%q)


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:
def gcd(a,b,c):
    gcd=0
    for i in range(1, a+1):
        if a%(a+1-i)==0 and b%(a+1-i)==0 and c%(a+1-i)==0:
            gcd=a+1-i
            break
    return gcd
def Sum(K):
    s=0
    for i in range(1,K+1):
        for j in range(1,K+1):
            for l in range(1,K+1):
                s=s+gcd(i,j,l)
    return s
print(Sum(int(input())))

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

N = int(input())
count = 0

def gcd(x, y):
    while(1):
        Q = x%y
        if Q == 0:
            return y
        else:
            x = y
            y = Q

for a in range(1,N+1):
    for b in range(1,N+1):
        for c in range(1,N+1):
            L = []
            M = []
            L += [a,b,c]
            L.sort(reverse=True)
            try:
                AB = gcd(L[0], L[1])
            except ZeroDivisionError:
                print(a,b,c)
            M += [L[2], AB]
            M.sort(reverse=True)
            try:
                count += gcd(M[0], M[1])
            except ZeroDivisionError:
                print(a,b,c)
print(count)

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 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
from functools import reduce

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

K=int(input())
sum=0


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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=q
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)

K = readInt()
def gcd(a,b,c):
	return math.gcd(math.gcd(a,b),c)
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 gcd(p, q):
    while q != 0:
        r = p % q
        p = q
        q = r
    return p

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input().strip())
gcdsum = 0

for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            gcdsum += math.gcd(math.gcd(a, b), c)
print(gcdsum)

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):
      gcd=math.gcd(a,b)
      gcd=math.gcd(gcd,c)
      ans+=gcd
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:
def gcd(i: int, j: int) -> int:
    if j == 0:
        return i
    return gcd(j, i % j)


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

print(res)

Submission status: Time Limit Exceeded

Solution code:
import math
K=int(input())
k=0
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)
            d=math.gcd(d,c)
            k+=d
print(k)

Submission status: Time Limit Exceeded

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]
 
sys.setrecursionlimit(1000000)
mod = 1000000007
 
def solve():
    def gcd(a,b):
        if a == 0:
            return b
        return gcd(b%a, a)
    k = I()
    ans = 0
    for a in range(1,k+1):
        for b in range(1,k+1):
            g = gcd(a,b)
            for c in range(1,k+1):
                ans += gcd(g,c)
    print(ans)
    return
 
#Solve
if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

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

  K = int(input())
  ans = 0
  for a in range(1,K+1):
    for b in range(1,K+1):
      g = gcd(a,b)
      for c in range(1,K+1):
        ans += gcd(g,c)
  print(ans)
  return
  
  
#Solve
if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
import math
k=int(input())
list=[]
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      list.append(math.gcd(math.gcd(a,b),c))
print(sum(list))

Submission status: Time Limit Exceeded

Solution code:

import math

k = int(input())

cache = {}
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            key = tuple(sorted([a,b,c]))
            x = cache.get(key, math.gcd(math.gcd(a, b), c))
            ans = ans + x
            cache[key] =  x
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())

cache = {}
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 + cache.get( (a,b,c), 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(i,math.gcd(j,k))
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math

K=int(input())
sum=0

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

        
print(sum)

Submission status: Time Limit Exceeded

Solution code:
def sort_2(a,b):
    if b<a:
        c=a
        a=b
        b=c
    return [a,b]


def GCDbase(a,b):
    D=b//a
    if b==D*a:
        return a
    else:
        return GCD(b-a*D,a)
    
def GCD(a,b):
    ab=sort_2(a,b)
    return GCDbase(ab[0],ab[1])

K=int(input())
sum=0
for i in range(1,K+1):
    for j in range(1,K+1):
        t=GCD(i,j)
        for l in range(1,K+1):

            sum+=GCD(t,l)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
def sort_2(a,b):
    if b<a:
        c=a
        a=b
        b=c
    return [a,b]


def GCDbase(a,b):
    D=b//a
    if b==D*a:
        return a
    else:
        return GCD(b-a*D,a)
    
def GCD(a,b):
    ab=sort_2(a,b)
    return GCDbase(ab[0],ab[1])
    
    
def sort_3(a,b,c):
    if b<a:
        d=a
        a=b
        b=d
    if c<b:
        d=c
        c=b
        b=d
    if b<a:
        d=a
        a=b
        b=d
    return [a,b,c]

def gcd(a,b,c):
    abc=sort_3(a,b,c)
    a=abc[0]
    b=abc[1]
    c=abc[2]
    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 l in range(1,K+1):
            sum+=gcd(i,j,l)
print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def GCD(a,b):
    if b<a:
        c=a
        a=b
        b=c
    D=b//a
    if b==D*a:
        return a
    else:
        return GCD(b-a*D,a)

def sort_3(a,b,c):
    if b<a:
        d=a
        a=b
        b=d
    if c<b:
        d=c
        c=b
        b=d
    if b<a:
        d=a
        a=b
        b=d
    return [a,b,c]

def gcd(a,b,c):
    abc=sort_3(a,b,c)
    a=abc[0]
    b=abc[1]
    c=abc[2]
    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+=gcd(i,j,k)
print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
##########
import math
#import numpy as np
from itertools import product as prod
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr

ii = lambda:int(input())
li = lambda:list(map(int,input().split()))
##########
def main(k):
    res = 0
    for item in prod(range(1,k+1),repeat=3):
        res += calc(item)
    return res
        
def calc(item):
    a,b,c = item
    return math.gcd(a,math.gcd(b,c))

k = ii()
print(main(k))

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 numpy as np
ans = 0
k = int(input())
A = k
B = k
C = k
for a in range(1,A+1):
    for b in range(1,B+1):
        for c in range(1,C+1):
            ans += np.gcd.reduce([a,b,c])
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:
def gcd(m,n):
    while (m % n != 0):
        temp = n
        n = m % n
        m = temp
    return(n)


k = int(input())
s = 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):
            s += gcd(t,c)
print(s)

Submission status: Time Limit Exceeded

Solution code:
def gcd(m,n):
    while (m % n != 0):
        temp = n
        n = m % n
        m = temp
    return(n)


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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
result = 0
import fractions

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
import math
k = int(input()) + 1
total = 0

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

print(total)

Submission status: Time Limit Exceeded

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

def gcd2(a,b,c):
    d=math.gcd(a,b)
    e=math.gcd(c,d)
    return e
    
s=0
for i1 in range(1,n+1):
    for i2 in range(1,n+1):
        for i3 in range(1,n+1):
            s+=gcd2(i1,i2,i3)

print(s)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

def gcd(a,b,c):
    d=min(a,b,c)
    for i in range(0,d):
        if a%(d-i)==0 and b%(d-i)==0 and c%(d-i)==0:
            return d-i
            break

s=0
for i1 in range(1,n+1):
    for i2 in range(1,n+1):
        for i3 in range(1,n+1):
            s+=gcd(i1,i2,i3)

print(s)

Submission status: Time Limit Exceeded

Solution code:
def gcd(x, y):
    if x < y:
        x, y = y, x
    while x % y != 0:
        x, y = y, x % y
    return y


def gcd_3(x, y, z):
    x_y = gcd(x, y)
    return gcd(x_y, z)


K = int(input())
ans = 0

sum_list = []


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

K = int(input())

sum = 0

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
def gcd(x, y):
    if x < y:
        x, y = y, x
    while x % y != 0:
        x, y = y, x % y
    return y


def gcd_3(x, y, z):
    x_y = gcd(x, y)
    return gcd(x_y, z)


K = int(input())
ans = 0

sum_list = []


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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
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):
      gcd = math.gcd(k, math.gcd(i, j))
      sum = sum + gcd
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
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):
      gcd = reduce(math.gcd, (i,j,k))
      sum = sum + gcd
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
n=int(input())
suma=0
for x in range(1,n+1):
    for y in range(1,n+1):
        for z in range(1,n+1):
            suma+=math.gcd(x,math.gcd(y,z))
print(suma)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())

sum=0

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


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)

Submission status: Time Limit Exceeded

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

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

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())+1

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

K = int(input())

K_list = [i+1 for i in range(K)]
res = 0

for i in range(len(K_list)):
  a = K_list[i]
  for j in range(len(K_list)):
    b = K_list[j]
    for k in range(len(K_list)):
      c = K_list[k]
      GCD = np.gcd.reduce([a, b, c])
      res += GCD

print(res)

Submission status: Time Limit Exceeded

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

print(total)

Submission status: Time Limit Exceeded

Solution code:
#abc162 c
import math
k = int(input())
def gcds(x,y,z):
    n1 = math.gcd(x,y)
    n2= math.gcd(n1,z)
    return n2
total = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for t in range(1,k+1):
            total += gcds(i,j,t)
print(total)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

K = int(input())

cnt = 0

for i in range(K):
  for j in range(K):
    for k in range(K):
      x = np.array([i+1, j+1, k+1])
      cnt += np.gcd.reduce(x)

print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

  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)
  return ans

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', 'i8(i8)')(solve)
    cc.compile()

if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    #from my_module import solve
    print(solve(int(input())))

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

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

def gcd_plus(a,b,c):
  num_list = [a,b,c]
  ans = num_list[0]
  for i in range(1,3):
    ans = math.gcd(ans,num_list[i])
  return ans

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

Submission status: Time Limit Exceeded

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

def gcd_plus(a,b,c):
  num_list = [a,b,c]
  N = len(num_list)
  ans = num_list[0]
  for i in range(1,N):
    ans = math.gcd(ans,num_list[i])
  return ans

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

Submission status: Time Limit Exceeded

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

def gcd_plus(a,b,c):
  num_list = [a,b,c]
  num_list.sort()
  for i in range(2):
    num_list[i+1] = math.gcd(num_list[i],num_list[i+1])
  return num_list[2]

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

Submission status: Time Limit Exceeded

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

print(sum)

Submission status: Time Limit Exceeded

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

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

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

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




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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math

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




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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math

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

print(sum)            



#a = list(map(int, input().split()))
#ans = a[0]
#for i in range(1, N):
#    ans = fractions.gcd(ans, a[i])
#print(ans)

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

print(sum)

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