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())
import fractions
x=0
c=0
d=0
for i in range(1,k+1):
  for j in range(i,k+1):
    for k in range(j,k+1):
      d=fractions.gcd(i,j)
      c=fractions.gcd(d,k)
      if i!=j and j!=k:
        x+=6*c
      elif (i!=j and j==k) or (k!=i and i==j):
        x+=3*c
      else:
        x+=c
print(x)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math


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


def main() -> None:
    k = int(input())

    s = sum(gcd(a, b, c) for a, b, c in itertools.product(range(1, k + 1), repeat=3))
    print(s)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
import collections

k = int(input())
gcd_table = [[0] * k for i in range(k)]
ans = 0
combination_list = [0, 1, 3, 6]
for p in range(1, k+1):
    for q in range(p, k+1):
        if gcd_table[p-1][q-1] == 0:
            tmp_gcd = math.gcd(p, q)
            gcd_table[p-1][q-1] = tmp_gcd
        else:
            tmp_gcd = gcd_table[p-1][q-1]
        for r in range(q, k+1):
            if gcd_table[q-1][r-1] == 0:
                tmp_gcd_2 = math.gcd(q, r)
                gcd_table[q-1][r-1] = tmp_gcd_2
            else:
                tmp_gcd_2 = gcd_table[q-1][r-1]
            unique_num = len(collections.Counter([p, q, r]))
            ans += math.gcd(tmp_gcd, tmp_gcd_2) * combination_list[unique_num]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
from functools import lru_cache
@lru_cache(maxsize = None)


def gcdx(x,y,z):
    return gcd(gcd(x,y),z)
n = int(input())
a = 0
longp = []

for i in range(1,n+1):
    for j in range(1,n+1):
        for p in range(1,n+1):
            a += gcdx(i,j,p)
           
print(a)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
  
def gcd3(a,b,c):
    return gcd(gcd(a,b),c)
    
k= int(input())    
total = 0
for i in range(1,k+1):
    for ii in range(1,k+1):
        for iii in range(1,k+1):
            total += gcd3(i,ii,iii)

print(total)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

def gcdx(x,y,z):
    return gcd(gcd(x,y),z)
n = int(input())
a = 0
longp = []

for i in range(1,n+1):
    for j in range(1,n+1):
        for p in range(1,n+1):
            a += gcdx(i,j,p)
           
print(a)

Submission status: Time Limit Exceeded

Solution code:
dic = {}
def gcd1(x, y):
  while(y):
    x, y = y, x % y 
  return x
 
def gcd(a,b,c):
  s = str(a)+","+str(b)+","+str(c)
  if s in dic.keys():
    return(dic[s])
  else:
    ans = gcd1(a,gcd1(b,c))
    dic[s] = ans
    return(ans)
 
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:

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

K = int(input())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

import math 

def gcds(l):
    res=0
    for val in l:
        res=math.gcd(res,val)
    return res
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for m in range(1,k+1):
            ans+=gcds([i,j,m])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
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())

# ans_array = np.zeros((k, k, k), dtype = np.int)

ans = 0

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

# print(ans_array)

# ans = np.sum(ans_array)

print(ans)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
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())

ans_array = np.zeros((k, k, k), dtype = np.int)

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

# print(ans_array)

ans = np.sum(ans_array)

print(ans)

Submission status: Time Limit Exceeded

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


N = int(input())

s = 0

for i in range(N):
    for j in range(N):
        ss = euclidean(i+1,j+1)
        for k in range(N):
            s +=euclidean(ss,k+1)

print(s)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b,c):
  min = a
  if b<a and b<c:
    min = b
  elif c<a and c<b:
    min = c
  ans = 1
  if a%min==0 and b%min==0 and c%min==0:
    ans = min
  else:
    for i in range(2,min):
      if a%i==0 and b%i==0 and c%i==0:
        ans = i
  return(ans)
 
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:

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

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

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
l = []
for i in range(1,k+1):
    for j in range(1,k+1):
        a,b = max(i,j),min(i,j)
        while b > 0:
            a,b = b,a%b
        for n in range(1,k+1):
            if a==1 or a==n:
                l.append(a)
            else:
                c,d = max(a,n),min(a,n)
                while d > 0:
                    c,d = d,c%d
                l.append(c)
print(sum(l))

Submission status: Time Limit Exceeded

Solution code:
import math


temp = 0
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 == B) and (A == C)):
                sum = sum + A
            elif((B == C) and ( A != C)):
                temp = math.gcd(A,B)
                sum = sum + (3 * math.gcd(temp,C))
            elif(((A == B) and (A != C)) or ((A == C) and (A != B))):
                sum = sum + 0
            else:
                temp = math.gcd(A,B)
                sum = sum + math.gcd(temp,C)
print(sum)

Submission status: Time Limit Exceeded

Solution code:

# -*- coding: utf-8 -*-
import math
K=int(input())

count=0

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            cal=math.gcd(math.gcd(a,b),c) 
            #print(cal)
            count+=cal
            

print(count)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
import functools

k = int(input())
li = [i for i in range(1,k+1)]
all_li = list(itertools.product(li, repeat=3))
ans = 0
for a in all_li:
    ans += functools.reduce(math.gcd, a)
print(ans)

Submission status: Time Limit Exceeded

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

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):
      y=list([i,j,k])
      z=len(y)//3
      for h in range(0,z):
        x=math.gcd(y[0],y[1])
        p=math.gcd(x,y[2])
        sum=sum+p
print(sum)

Submission status: Time Limit Exceeded

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

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

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

res = 0

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

print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
import fractions
x=0
c=0
d=0
for i in range(1,k+1):
  for j in range(i,k+1):
    for k in range(j,k+1):
      d=fractions.gcd(i,j)
      c=fractions.gcd(d,k)
      if i!=j and j!=k and k!=i:
        x+=6*c
      elif (i!=j and j==k) or (j!=k and k==i) or (k!=i and i==j):
        x+=3*c
      else:
        x+=c
print(x)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

l = [[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(reduce(gcd,l)))
ans = 0
for i in l:
  ans += reduce(gcd,i)
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())
t = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for l in range(1,K+1):
            t = t + gcd(i,j,l)
print(t)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
import math
count = 0
for i in range(num):
    for i2 in range(num):
        for i3 in range(num):
            count += math.gcd(math.gcd(i + 1,i2 + 1),i3 + 1)
print(count)

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

Submission status: Time Limit Exceeded

Solution code:
k=int(input())

import math
 
res=0
 
for n in range(1,k+1):
    for i in range(1,k+1):
        for j in range(1,k+1):

            res+=math.gcd(math.gcd(n,i),j)

print(res)

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

print(total)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K = int(input())
output = 0
for i1 in range(1,K+1):
    for i2 in range(1,K+1):
        for i3 in range(1,K+1):
            output += gcd(i1,i2,i3)
print(output)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
A=0
def GCD(a,b):
    if a%b==0:
        return b
    return GCD(b,a%b)
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
import itertools
from functools import reduce

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

K = int(input())

i = list(range(1,K+1))

j = itertools.product(i,i,i)

total = 0
for x in j:
  total += gcd(*x)
   
print(total)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
a = []

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

for i in range(1, k+1):
    for j in range(1, k+1):
        x = gcd(i, j)
        for l in range(1, k+1):
            y = gcd(l, x)
            a.append(y)
print(sum(a))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
k=int(input())

import math
 
res=0
 
for n in range(1,k+1):
    for i in range(1,k+1):
        for j in range(1,k+1):

            ni=math.gcd(n, i)
            res+=math.gcd(ni,j)

print(res)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import math

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

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


print(ans)

Submission status: Time Limit Exceeded

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

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
from math import gcd

k = int(input())

result = 0
for a, b, c in product(range(1, k+1), repeat=3):
    result += gcd(a, gcd(b, c))

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

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

Submission status: Time Limit Exceeded

Solution code:
from sys import setrecursionlimit
setrecursionlimit(1000000)

def Euclid_algorithm(a:int, b:int)->int:
    if a < b:
        a, b = b, a
    else:
        pass
    if b == 0:
        return a
    else:
        return Euclid_algorithm(b, a % b)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

k=int(input())
ans=0
for a in range(1,k+1):
    for b in range(1,a+1):
        for c in range(1,b+1):
            if (a==b) and (b==c):
                ans+=np.gcd(a,np.gcd(b,c))
            if ((a!=b) and (b==c)) or ((a==b) and (b!=c)):
                ans+=3*np.gcd(a,np.gcd(b,c))
            if ((a!=b) and (b!=c)):
                ans+=6*np.gcd(a,np.gcd(b,c))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(x,y):
    if y == 0:
        return x
    elif x == 1 or y == 1:
        return 1
    else:
        return gcd(y,x%y)


n = int(input())
i = 1
j = 1
k = 1
ans = 0
while i < n+1:
    j = 1
    while j < n+1:
        k = 1
        p = gcd(i,j)
        while k < n+1:
            ans += gcd(k,p)
            k += 1
        j += 1
    i += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
i = 1
j = 1
k = 1
ans = 0
while i < n+1:
    j = 1
    while j < n+1:
        k = 1
        while k < n+1:
            ans += math.gcd(i,math.gcd(j,k))
            k += 1
        j += 1
    i += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y,x%y)
n = int(input())
i = 1
j = 1
k = 1
ans = 0
while i < n+1:
    j = 1
    while j < n+1:
        k = 1
        while k < n+1:
            ans += gcd(i,gcd(j,k))
            k += 1
        j += 1
    i += 1
print(ans)

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()) +1
mydict = {}

# データパターンを求める式
ans = 0
for h in range(1, K):
  for i in range(1, K):
    for j in range(1, K):
      
      tmp = ''.join(map(str, sorted([h,i,j])))
      if tmp in mydict:
        ans += mydict[tmp]
      else:
        val = gcd(h,gcd(i,j))
        ans += val
        mydict[tmp] = val 

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(num1,num2):
    if num1 % num2 == 0:
        return num2
    return gcd(num2 , num1 % num2)

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):
            nums = gcd(i,j)
            total += gcd(nums,k)

print(total)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

k = int(input())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
sum = 0
 
def gcd(a, b, c):
    smaller = min(min(a, b), c)
    for i in range(1, smaller + 1):
        if (a % i == 0) and (b % i == 0) and (c % i == 0):
            gcd = i
    return gcd
 
for i in range (1, n + 1):
    for j in range (1, n + 1):
        for k in range(1, n + 1):
            sum += gcd(i, j, k)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
gcd_list=[]
i=int(input())
for x in range(1, i+1):
  for y in range(1, i+1):
    for z in range(1, i+1):
      gcd_list.append(gcd(x, y, z))
      
print(sum(gcd_list))

Submission status: Time Limit Exceeded

Solution code:
import fractions


k = int(input())

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

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:
def gcd(num1,num2):
    if num1 % num2 == 0:
        return num2
    return gcd(num2 , num1 % num2)

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):
            nums = 0
            nums = gcd(i,j)
            total += gcd(nums,k)

print(total)

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

Submission status: Time Limit Exceeded

Solution code:
def gcd(num1,num2):
    if num1 % num2 == 0:
        return num2
    return gcd(num2 , num1 % num2)

from functools import reduce

N = int(input())
gcds = []
total = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            nums = 0
            nums = gcd(i,j)
            total += gcd(nums,k)

print(total)

Submission status: Time Limit Exceeded

Solution code:
import fractions


k = int(input())
cache = dict()

def gcd(l):
    if tuple(sorted(l)) in cache:
        return cache[tuple(sorted(l))]
    ans = l[0]
    for i in range(1, len(l)):
        ans = fractions.gcd(ans, l[i])
    cache[tuple(sorted(l))] = ans
    return ans

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([a, b, c])
print(res)

Submission status: Time Limit Exceeded

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

def gcd(p,q):
    if p%q == 0:
        return q
    return gcd(q, p%q)
    
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            s += gcd(gcd(a,b),c)
            
print(s)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

s = 0
k = int(input())

def gcd(p,q):
    if p%q == 0:
        return q
    return gcd(q, p%q)
    
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            s += gcd(gcd(a,b),c)
            
print(s)

Submission status: Time Limit Exceeded

Solution code:
import math
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 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:
k=int(input())
sum=0

def gcd(x,y):
  while y!=0:
    x,y=y,x%y
  return x
    
for i in range(1,k+1):
  for j in range(1,k+1):
    for z in range(1,k+1):
      sum+=gcd(i,gcd(j,z))
      
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import math

N = int(input())
gcds = []
num = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            gcds.append(reduce(math.gcd,[i,j,k]))

print(sum(gcds))

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

# データパターンを求める式
ans = 0
for h in range(1, K):
  for i in range(1, K):
    for j in range(1, K):
      # 最小公倍数算出
      ans += gcd(h,gcd(i,j))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
k=int(input())
 
from math import gcd
s6=0
for i in range(2,k-1):
    for j in range(i+1,k):
        for jj in range(j+1,k+1):
            s6+=np.gcd(np.gcd(i,j),jj)
 
s3=0
for i in range(2,k):
    for j in range(i+1,k+1):
        s3+=np.gcd(i,j)
 
s1=int((k+1)*k/2)
 
 
print(s1+s3*6+s6*6+(k-1)*6+(k-2)*(k-1)*3)

Submission status: Time Limit Exceeded

Solution code:
import math

K=int(input())
ans=0

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

Submission status: Time Limit Exceeded

Solution code:

K = int(input())

def func_gcd(a, b):
    if b > a:
        a, b = b, a
    
    while b > 0:
        r = a % b
        a = b
        b = r

    return a

ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for l in range(1, K + 1):
            temp = func_gcd(i, j)
            temp2= func_gcd(temp, l)
            ans += temp2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#%%
K = int(input())

def func_gcd(a, b):
    if b > a:
        a, b = b, a
    
    while b > 0:
        r = a % b
        a = b
        b = r

    return a

ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        temp = func_gcd(i, j)
        for l in range(1, K + 1):
            temp2= func_gcd(temp, l)
            ans += temp2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

def mgcd(*a):
    return reduce(gcd, a)

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 += mgcd(i, j, l)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

k = int(input())

res = 0
mul = [0, 1, 3, 6]
for a in range(1, k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            res += gcd(gcd(a, b), c) * mul[len({a, b, c})]

print(res)

Submission status: Time Limit Exceeded

Solution code:
import queue
import copy
import fractions
from collections import deque
import bisect


N = int(input())
sum = 0
for a in range(1, N+1):
    if a == 1:
        sum += 1 * N**2
        continue

    for b in range(1, N+1):
        if b == 1:
            sum += 1 * N
            continue

        for c in range(1,N+1):
            if c == 1:
                sum += 1
                continue
            sum += fractions.gcd(fractions.gcd(a, b), c)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())

ans =0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

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

Submission status: Time Limit Exceeded

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

ans=0
for i in range(k):
    ans+=i+1
    for j in range(i+1, k):
        x=gcd(i+1,j+1)
        ans+=6*gcd(i+1,j+1)
        for l in range(j+1, k):
            ans+=6*gcd(x,l+1)
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 h in range(1,k+1):
      ans+=math.gcd(math.gcd(i,j),h)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math


K=int(input())

ans=0

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

print(ans)

Submission status: Time Limit Exceeded

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

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