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 math
K = int(input())
total = 0
for x in range(1, K+1):
    for y in range(1, K+1):
        for z in range(1, K+1):
            total = total+math.gcd(x, math.gcd(y, z))
print(total)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

k = int(input())
s = 0

for h in range(1, k+1):
    for i in range(1, k+1):
        for j in range(1, k+1):
            s += gcd(gcd(h, i), j)

print(s)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import math

k = int(input())

s = 0

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

for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            s += gcd(i,j,l)

print(s)

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())
k_range = range(1, k + 1)

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


sum_gcd = 0
for l in k_range:
    for m in k_range:
        for n in k_range:
            sum_gcd += math.gcd(n, math.gcd(l, m))

print(sum_gcd)

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
k = int(input())
k_range = range(1, k + 1)


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


sum_gcd = 0
for l in k_range:
    for m in k_range:
        for n in k_range:
            sum_gcd += gcd(n, gcd(l, m))

print(sum_gcd)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce


def gcd_list(numbers):
    return reduce(math.gcd, numbers)
K = int(input())
count = 0 
a = [0,0,0]
for i in range(1,K+1):
  a[0] = i
  for j in range(1,K+1):
    a[1] = j
    for k in range(1,K+1):
      a[2] = k
      count += gcd_list(a)


print(count)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
k=int(input())
cnt=0
for i in range(1,k+1):
  for p in range(1,k+1):
    for q in range(1,k+1):
      gcd1=gcd(i,p)
      gcd2=gcd(p,q)
      cnt+=gcd(gcd1,gcd2)

      
print(cnt)

Submission status: Time Limit Exceeded

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

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

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
from functools import reduce
K = int(input())
ans = 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):
      ans += gcd(i, j, k)
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b):
  while b!=0:
    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):
    ab = gcd(a,b)
    for c in range(1, K+1):
      ans += gcd(ab,c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations_with_replacement

K = int(input())
k_range = list(range(1, K+1))

result = 0
for comb in combinations_with_replacement(k_range, 3):
    min_abc = min(comb)
    for i in range(min_abc, 0, -1):
        if (comb[0]%i == 0 and comb[1]%i == 0) and comb[2]%i == 0:
            if comb[0]==comb[1] and comb[1]==comb[2]:
                coef = 1
            elif (comb[0]!=comb[1] and comb[1]!=comb[2]) and comb[2]!=comb[0]:
                coef = 6
            else:
                coef = 3
            result += i * coef
            break
print(result)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K = int(input())

sum = 0

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
n=int(input())
l=0
summ=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(i,j,)
      ans=math.gcd(ans,k)
      summ+=ans
print(summ)

Submission status: Time Limit Exceeded

Solution code:
import math
k = int(input())
ans = 0
for i in range (k) :
    for j in range (k) :
        for l in range (k) :
            p = math.gcd(i+1,j+1)
            if abs(i-j) == 1 :
                ans += 1
            elif abs(j-l) == 1 :
                ans += 1
            elif abs(l-i) == 1 :
                ans += 1
            elif p == 1 :
                ans += 1
            else :
                ans += math.gcd(p,l+1)

print(ans)

Submission status: Time Limit Exceeded

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

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

ans = 0
d = dict()
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            x = [str(i) for i in sorted([a, b, c])]
            key = ''.join(x)
            if key not in d.keys():
                d[key] = gcd(a, b, c)
            ans += d[key]
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            ans+=gcd(i,j,k)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np

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

Submission status: Time Limit Exceeded

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

def f(p, n):
  if len(p) == 3:
    global ans
    t = gcd(p[0], p[1])
    t = gcd(t, p[2])
    ans += t
    return t
  for i in range(1, n+1):
    f(p+[i], n)
  
ans = 0
k = int(input())
f([], k)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
n=int(input())
cnt=0
for i in range(1,n+1):
  for j in range(1,n+1):
    a=gcd(i,j)
    for k in range(1,n+1):
      cnt+=gcd(a,k)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
k=int(input())
cnt=0
for i in range(1,k+1):
  for j in range(1,k+1):
    a=gcd(i,j)
    for k in range(1,k+1):
      cnt+=gcd(a,k)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import functools
import math

K = int(input())

def gcd_2(*vals):
    return functools.reduce(math.gcd, vals)

ans=0
for x in range(1,K+1):
    for y in range(1,K+1):
        for z in range(1,K+1):
            ans += gcd_2(x,y,z)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np
from functools import reduce

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

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

K = int(input())

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np
from functools import reduce

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

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

K = int(input())

ans = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce


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


def main():
    K = int(input())
    s = sum([gcd(i+1, j+1, k+1) for i in range(K) for j in range(K) for k in range(K)])

    print(s)


if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

def mygcd(x,y):
    a = min(x,y)  # 最小値
    b = max(x,y)  # 最大値
    r = 2  # 余り
    while r != 0:
        r = b % a
        b = a
        a = r
    return b

ans = 0
for i in range(k):
    for j in range(k):
        for l in range(k):
            ans += mygcd(mygcd(i+1,j+1),l+1)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

def mygcd(x,y):
    a = min(x,y)  # 最小値
    b = max(x,y)  # 最大値
    r = 2  # 余り
    while r != 0:
        r = b % a
        b = a
        a = r
    return b

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

def mygcd(x,y):
    a = min(x,y)  # 最小値
    b = max(x,y)  # 最大値
    q = 2  # 商
    r = 2  # 余り
    while r != 0:
        q = b / a
        r = b % a
        b = a
        a = r
    return b

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

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

import math
import itertools
num_list = list(list(itertools.product(range(1,k+1), repeat=3)))

sum_ = 0
for i,j,k in num_list:
    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(i, math.gcd(j, k))
print(sum_)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

l =0
for i in range(1,k+1):
  for i2 in range(1,k+1):
    for i3 in range(1,k+1):
      l+=reduce(math.gcd,[i,i2,i3])
print(l)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

k = int(input())
a = [i for i in range(1, k + 1)]
b = [i for i in range(1, k + 1)]
c = [i for i in range(1, k + 1)]

ans = 0
for x, y, z in itertools.product(a, b, c):
  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 x in range(1,k+1):
            ans +=math.gcd(i,math.gcd(j,x)) 

            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np
k = int(input())

Map = [[0 for j in range(k)] for i in range(k)]
for i  in range(1,k+1):
    for j in range(1,k+1):
        tmp = math.gcd(i,j)
        Map[i-1][j-1] = tmp
        Map[j-1][i-1] = tmp

ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for x in range(1,k+1):
            tmp = [i,j,x]
            tmp_ans = Map[tmp[0]-1][tmp[2]-1]
            ans += Map[tmp_ans-1][tmp[1]-1]
            
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def gcd(*numbers):
    return reduce(math.gcd, numbers)
def do():
    k=INT()
    ans=0
    for i in range(1,k+1):
        for j in range(1,k+1):
            for h in range(1,k+1):
                ans+=gcd(i,j,h)
                #print(ans,i,j,h)
    print(ans)
if __name__ == '__main__':
    do()

Submission status: Time Limit Exceeded

Solution code:
import itertools

def U1(a,b):
    if b > a:
        b, a = a, b
    while a%b != 0:
        r = a%b
        a = b
        b = r
    return b

K = int(input())
c = 0

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

print(c)

Submission status: Time Limit Exceeded

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

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

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

print(sum)

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

Submission status: Time Limit Exceeded

Solution code:
"""
def gcd(a, b ):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b
"""
import math as f


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

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

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

def gcd(a, b, c):
    mini = a
    if a > b:
        mini = b
    if b > c:
        mini = c
    if (a % mini == 0) & (b % mini == 0) & (c % mini == 0):
        return mini
    for i in range((mini + 1)//2 + 1, 1, -1):
        if (a % i == 0) & (b % i == 0) & (c % i == 0):
            return i
    return 1

s = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            a = gcd(i, j, l)
            s += int(a)

print(s)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

def gcd(a, b, c):
    mini = a
    if a > b:
        mini = b
    if b > c:
        mini = c
    for i in range(mini + 1, 1, -1):
        if (a % i == 0) & (b % i == 0) & (c % i == 0):
            return i
    return 1

s = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            a = gcd(i, j, l)
            s += int(a)

print(s)

Submission status: Time Limit Exceeded

Solution code:
import math

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

print(s)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

K = int(input())
total = 0


def gcd_list(*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):
            s = [i, j, k]
            total += gcd_list(*s)

print(total)

Submission status: Time Limit Exceeded

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


def ab_gcd(a: int, b: int):
    small = min(a, b)
    large = max(a, b)
    r = large % small
    if r != 0:
        return ab_gcd(r, small)
    else:
        return small


for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            gcd1 = ab_gcd(i, j)
            gcd2 = ab_gcd(k, gcd1)
            if i == j == k:
                total += gcd2
            elif i == j and j != k:
                total += gcd2 * 3
            elif i != j and j == k:
                total += gcd2 * 3
            else:
                total += gcd2 * 6

print(total)

Submission status: Time Limit Exceeded

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


def ab_gcd(a: int, b: int):
    small = min(a, b)
    large = max(a, b)
    r = large % small
    if r != 0:
        return ab_gcd(r, small)
    else:
        return small


for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            gcd1 = ab_gcd(i, j)
            gcd2 = ab_gcd(j, k)
            gcd3 = ab_gcd(gcd1, gcd2)
            if i == j == k:
                total += gcd3
            elif i == j and j != k:
                total += gcd3 * 3
            elif i != j and j == k:
                total += gcd3 * 3
            else:
                total += gcd3 * 6

print(total)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
k= int(input())
ans = 0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      g = math.gcd(a,b)
      g = math.gcd(g,c)
      ans = ans + g
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):
      g=math.gcd(a,b)
      g=math.gcd(g,c)
      ans=ans+g
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from math import gcd

N = int(input())
print(sum([reduce(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)]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

def gcd(l):
    ans = l[0]
    for i in l:  ans = gcd_(ans, i)
    return ans

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import fractions
a=0
N=int(input())
for i in range(1,N+1):
  for j in range(1,N+1):
    for k in range(1,N+1):
      c=fractions.gcd(i,j)
      a+=fractions.gcd(c,k)
print(a)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
k = int(input())
sum = 0
for i in range (1,k+1):
    for x in range (1,k+1):
        for _ in range (1,k+1):
            y = math.gcd(i,x)
            sum += math.gcd(y,_)


print(sum)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools

n = int(input())
ans =0
for a,b,c in itertools.product(range(1,n+1),repeat=3):

    g = np.gcd(np.gcd(a,b),c)
    ans +=g
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

List=[euclid(euclid(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(List))

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())
g = []

for a in range(k):
  for b in range(k):
    for c in range(k):
      g.append(math.gcd(math.gcd(a+1,b+1),c+1))

print(sum(g))

Submission status: Time Limit Exceeded

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

K = int(input())
""" answer 1
ans = 0
tmp = {}
for i in range(201):
    tmp[i] = 0

for i in range(1, K +1):
    for j in range(1, K +1):
        tmp[math.gcd(i, j)] += 1

for k in range(1, K +1):
    for key in tmp.keys():
        ans += math.gcd(key, k) * tmp[key]
print(ans)

"""

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

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
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(gcd(a,b),c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# atcoder 
# Türkçe konuşyorum
# Türkler var mı?
# memnün oldum
import sys
import math


sys.setrecursionlimit(10 ** 8)

#def divmin
#for i in range(d, 1, -1):
#    if(d % i == 0):
#        print(i)
def pgcd(a, b):
    while b!=0:
        a,b=b,a%b
    return a

def msum(a, b, c):
    if (a <= b) and (a <= c): 
        return math.gcd(a, math.gcd(b,c))
        #while(a >= 1):
        #    if (b % a == 0) and (c % a == 0):
        #        return a
            
    elif (b <= a) and (b <= c):
        return(math.gcd(b, math.gcd(a,c)))
    elif (c <= a) and (c <= b):
        return math.gcd(c, math.gcd(a,b))
    else:
        print("Grande érreur dans ta tête!!!")

def çözmek(num):
    csum = 0
    for i in range(1, num+1):
        for j in range(1, num+1):
            for l in range(1, num+1):
                #print(i,j,l)
                #csum += msum(i,j,l)
                csum += pgcd(i, pgcd(j,l))

    return csum


if __name__ == "__main__":
    K = int(input())
    print(çözmek(K))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# atcoder 
# Türkçe konuşyorum
# Türkler var mı?
# memnün oldum
import sys
import math


sys.setrecursionlimit(10 ** 8)

#def divmin
#for i in range(d, 1, -1):
#    if(d % i == 0):
#        print(i)
def pgcd(a, b):
    while b!=0:
        a,b=b,a%b
    return a

def msum(a, b, c):
    if (a <= b) and (a <= c): 
        return math.gcd(a, math.gcd(b,c))
        #while(a >= 1):
        #    if (b % a == 0) and (c % a == 0):
        #        return a
            
    elif (b <= a) and (b <= c):
        return(math.gcd(b, math.gcd(a,c)))
    elif (c <= a) and (c <= b):
        return math.gcd(c, math.gcd(a,b))
    else:
        print("Grande érreur dans ta tête!!!")

def çözmek(num):
    csum = 0
    for i in range(1, num+1):
        for j in range(1, num+1):
            for l in range(1, num+1):
                #print(i,j,l)
                csum += msum(i,j,l)


    return csum


if __name__ == "__main__":
    K = int(input())
    print(çözmek(K))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
from math import gcd
from itertools import product
L=tuple(product([i for i in range(1,k+1)],repeat=3))
s=0
for a,b,c in L:
    a=gcd(a,b)
    s+=gcd(a,c)
print(s)