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 sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np
 
K = INT()
sum = 0
 
for n in range(1, K+1):
  for m in range(1, K+1):
    for l in range(1, K+1):
      sum += gcd(n, gcd(m, l))
 
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
def INT(): return int(input())
 
 
K = INT()
sum = 0
 
for n in range(K):
  for m in range(K):
    for l in range(K):
      sum += gcd(gcd(n+1, m+1), l+1)
 
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
def INT(): return int(input())
 
 
K = INT()
sum = 0
 
for n in range(K):
  for m in range(K):
    for l in range(K):
      sum += gcd(n+1, gcd(m+1, l+1))
 
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
def INT(): return int(input())

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

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np
 
K = INT()
sum = 0
 
for n in range(K):
  for m in range(K):
    for l in range(K):
      sum += gcd(n+1, gcd(m+1, l+1))
 
print(sum)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def cgd(x, y):
    if y == 0: return x
    else: return cgd(y, x % y)
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 += cgd(cgd(a, b), c)
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):
      ans=math.gcd(math.gcd(i,j),k)
      sum=sum+ans
      
print(sum)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
N = 3
def common_divisor(num1,num2):
    max_n = max(num1,num2)
    min_n = min(num1,num2)
    temp = max_n%min_n
    while True:
        if temp:
            max_n = min_n
            min_n = temp
            temp = max_n%min_n
        else:
            return min_n

sum = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        temp = common_divisor(i,j)
        for m in range(1,K+1):
            sum = sum+common_divisor(m,temp)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
N = 3
def common_divisor(num1,num2):
    if num1%num2==0:
        return num2
    elif num2%num1==0:
        return num1
    temp = max(num1,num2)%min(num1,num2)
    while True:
        if temp!=0:
            num1 = min(num1,num2)
            num2 = temp
            temp = num1%num2
        else:
            return num2

sum = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for m in range(1,K+1):
            sum = sum+common_divisor(common_divisor(i,j),m)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def main():
   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)

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())


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


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

Submission status: Time Limit Exceeded

Solution code:
print(sum(__import__('functools').reduce(__import__('math').gcd,[a,b,c]) for a,b,c in __import__('itertools').product(range(1,int(input())+1), repeat=3)))

Submission status: Time Limit Exceeded

Solution code:
K=int(input())

memo={}
def gcd(a,b):
    if a<b:
        a,b=b,a

    aa=a
    bb=b
    if (a,b) in memo.keys():
        return memo[a,b]
    while b != 0:
        a,b, = b, a%b
    memo[aa,bb]=a
    return a





memo3={}

def gcd3(a,b,c):
    if a>b:
        a,b = b,a
    if a>c:
        a,c = c,a
    if b>c:
        b,c = c,b
    if (a,b,c) in memo3.keys():
        return memo3[(a,b,c)]
    
    g = gcd(gcd(a,b),c)
    memo3[(a,b,c)]=g
    return g


sum=0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            
            if i==j & j==k:
                sum += gcd3(i,j,k)
                continue
            if i==j & j!=k:
                sum += gcd3(i,j,k)*3
                continue
            if i!=j & j==k:
                sum += gcd3(i,j,k)*3
                continue
            sum += gcd3(i,j,k)*6
print(sum)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())

memo={}
def gcd(a,b):
    if a<b:
        a,b=b,a

    aa=a
    bb=b
    if (a,b) in memo.keys():
        return memo[a,b]
    while b != 0:
        a,b, = b, a%b
    memo[aa,bb]=a
    return a





memo3={}

def gcd3(a,b,c):
    if a>b:
        a,b = b,a
    if a>c:
        a,c = c,a
    if b>c:
        b,c = c,b
    if (a,b,c) in memo3.keys():
        return memo3[(a,b,c)]
    
    g = gcd(gcd(a,b),c)
    memo3[(a,b,c)]=g
    return g


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

Submission status: Time Limit Exceeded

Solution code:
from os import path
import sys
if(path.exists('C:/Users/prana/Desktop/sublime/input.txt')):
    sys.stdin = open("C:/Users/prana/Desktop/sublime/input.txt","r")
    sys.stdout = open("C:/Users/prana/Desktop/sublime/output.txt","w")

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

test_case = 1
while(test_case):
    solve()
    test_case -= 1

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

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 numpy as np

K = int(input())

gcd1 = np.sum(np.arange(1,K+1))
gcd2 = 0
gcd3 = 0

for a in np.arange(1,K):
    for b in np.arange(a+1,K+1):
        gcd_ab = np.gcd(a,b)
        gcd2 += gcd_ab
        for c in np.arange(b+1,K+1):
            gcd3 += np.gcd(gcd_ab,c)

print(gcd1 + 6*gcd2 + 6*gcd3)

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

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):
           x = math.gcd(a,b)
           y = math.gcd(x,c)
           list.append(y)
print(sum(list))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from functools import reduce
from math import gcd
import itertools

N = int(input())
intlist = list(range(1, N + 1))

total = 0
for v in itertools.product(intlist, repeat=3):
   a = reduce(gcd, v)
   total += a

print(total)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

K = int(input())
gcd = 0

gcd1 = np.sum(np.arange(1,K+1))
gcd2 = 0
gcd3 = 0
for a in np.arange(1,K-1):
    for b in np.arange(a+1,K):
        for c in np.arange(b+1,K+1):
            gcd_bc = np.gcd(b, c)
            gcd3 += np.gcd(a, gcd_bc)

for a in np.arange(1,K):
    for b in np.arange(a+1,K+1):
        gcd2 += np.gcd(a, b)

print(gcd1 + gcd2 * 6 + gcd3 * 6)

Submission status: Time Limit Exceeded

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

print(result)

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
trip = dict()
pair = dict()

def gcd(a, b):
    d = frozenset([a, b])
    if d in pair:
        return pair[d]

    if b == 0:
        pair[d] = a
        return a

    while b:
        a %= b
        a, b = b, a

    pair[d] = a
    return a

def gcd3(K):

    res = 0

    for i in range(1, K+1):
        for j in range(1, K+1):
            for k in range(1, K+1):
                l = frozenset([i, j, k])
                if l in trip:
                    res += trip[l]
                    continue

                x = gcd(i, gcd(j, k))
                # print("i:%d, j:%d, k:%d, x:%d" % (i, j, k, x))
                res += x
                trip[l] = x

    return res

print(gcd3(K))

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
trip = dict()

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

    while b:
        a %= b
        a, b = b, a

    return a

def gcd3(K):

    res = 0

    for i in range(1, K+1):
        for j in range(1, K+1):
            for k in range(1, K+1):
                l = frozenset([i, j, k])
                if l in trip:
                    res += trip[l]
                    continue

                x = gcd(i, gcd(j, k))
                # print("i:%d, j:%d, k:%d, x:%d" % (i, j, k, x))
                res += x
                trip[l] = x

    return res

print(gcd3(K))

Submission status: Time Limit Exceeded

Solution code:
import math

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

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8

k = int(input())
count = 0

def gcd(a,b):
    if a >= b:
        k1, k2 = a, b
    elif a < b:
        k1, k2 = b, a

    r = k1 % k2
    if r != 0:
        return gcd(k2,r)
    elif r == 0:
        return k2

for a in range(1,k+1):

    for b in range(1,k+1):

        f = gcd(a,b)

        for c in range(1,k+1):

            g = gcd(f,c)
            count += g

print("{}".format(count))

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
def gcd(x,y,z):
    List = [x,y,z]
    List.sort()
    if int(1) in List:
        return 1
    while True:
        if List[2] % List[1] !=0:
            mod = List[2] % List[1]
            List[2] = List[1]
            List[1] = mod
        else:
            gcd1 = List[1]
            break
    List2 = [List[0],gcd1]
    List2.sort
    while True:
        if List2[1] % List2[0] !=0:
            mod2 = List2[1] % List2[0]
            List2[1] = List2[0]
            List2[0] = mod2
        else:
            gcd2 = List2[0]
            break
    return gcd2
S = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            S += gcd(i,j,k)
print(S)

Submission status: Time Limit Exceeded

Solution code:
MAX_K: int = 200

gt = [[0 for _ in range(MAX_K + 1)] for _ in range(MAX_K + 1)]

def gcd(x: int, y: int) -> int:
    ret: int = 0
    if x < y:
        ret = gcd(y, x)
    elif y == 0:
        ret = x
    elif y == 1:
        ret = 1
    else:
        ret = gcd(y, x % y)
    gt[x][y] = ret
    # print(f"gcd({x}, {y}) = {ret}")
    return ret

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

Submission status: Time Limit Exceeded

Solution code:
def GCD(x,y):
  a = max([x,y])
  b = min([x,y])
  Dr = a % b
  while Dr != 0:
    a,b = b,Dr
    Dr = a % b
  return b

def sgcd(K):
  rt = 0
  for a in range(1,K+1):
    for b in range(1,K+1):
      for c in range(1,K+1):
        rt += GCD(GCD(a,b),c)
  return rt
K = int(input())
print(sgcd(K))

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

N=int(input())
count = 0
j_check = 0
k_check = 0

for i in range(1,N+1):
    i_ins=[]
    for x in range(1,i+1):
        if i//x != 0 and i%x == 0:
            i_ins.append(x)
    for j in range(1,N+1):
        i_j_ins=[]
        for y in i_ins:
            if j//y != 0 and j%y == 0:
                i_j_ins.append(y)
        for k in range(1,N+1):
            i_j_k_ins=[]
            for z in reversed(i_j_ins):
                if k//z != 0 and k%z == 0:
                    i_j_k_ins.append(z)
                    break
            count = count + i_j_k_ins[-1]

print(count)

Submission status: Time Limit Exceeded

Solution code:
#! env/bin/local python3
# -*- coding:utf-8 -*-

# -- submit ----

# --- fetch input ---

inputs: list = []
while True:
    try:
        inputs.append(input().strip('\n'))
    except EOFError:
        break

# --- write code below ---

k = int(inputs[0])
r = range(1, k + 1)
ans = 0


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


for i in r:
    for j in r:
        for k in r:
            ans += gcd(gcd(i, j), k)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

import math
import itertools
from functools import reduce

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

h_list = []

for i in itertools.product(l, repeat=3):
    h_list.append(i)

a = 0

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

for val in h_list:
  a += gcd(val[0], val[1], val[2])
  
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 k in range(1,K+1):
            ans+=math.gcd(i,math.gcd(j,k))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = input()

#ユーグリッド互除法（再起）
def gcd(p, q):
  # ユーグリッド互除法
  if (p%q==0):
    return q
  else:
    return gcd(q, p%q)

ans = 0

#すべての組合せ(n^3)
abc_list = []
for a in range(1, int(K)+1):
  for b in range(1, int(K)+1):
    for c in range(1, int(K)+1):
        gcd_ab = gcd(a, b)
        gcd_abc = gcd(gcd_ab, c)
        ans += gcd_abc

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b):
    if a<b:
        a,b=b,a
    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:
K = input()

#すべての組合せをリスト化する
abc_list = []
for a in range(1, int(K)+1):
  for b in range(1, int(K)+1):
    for c in range(1, int(K)+1):
      abc_list.append([a, b, c])

#ユーグリッド互除法（再起）
def gcd(p, q):
  # ユーグリッド互除法
  if (p%q==0):
    return q
  else:
    return gcd(q, p%q)

# 回答
ans = 0
for lis in abc_list:
  a = lis[0]
  b = lis[1]
  c = lis[2]

  gcd_ab = gcd(a, b)
  gcd_abc = gcd(gcd_ab, c)

  ans += gcd_abc

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math


def gcd(a, b, c):

    return math.gcd(math.gcd(a, b), c)


k = int(input())
answer = 0
for w_a in range(1, k + 1):
    for w_b in range(1, k + 1):
        for w_c in range(1, k + 1):
            answer += gcd(w_a, w_b, w_c)

print(answer)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

a=int(input())
b=[]
for i in range(1,a+1):
    for j in range(1,a+1):
        for n in range(1,a+1):
            #print(i,j,n)
            c=reduce(math.gcd,[i,j,n])
            b.append(c)

print(sum(b))

Submission status: Time Limit Exceeded

Solution code:
K = input()

#すべての組合せをリスト化する
abc_list = []
for a in range(1, int(K)+1):
  for b in range(1, int(K)+1):
    for c in range(1, int(K)+1):
      abc_list.append([a, b, c])

#ユーグリッド互除法（再起）
def gcd(A, B):
  # p >= q とする
  if A >= B:
    p = A
    q = B
  else:
    p = B
    q = A
  
  # ユーグリッド互除法
  if (p%q==0):
    return q
  else:
    return gcd(q, p%q)

# 回答
ans = 0
for lis in abc_list:
  a = lis[0]
  b = lis[1]
  c = lis[2]

  gcd_ab = gcd(a, b)
  gcd_abc = gcd(gcd_ab, c)

  ans += gcd_abc

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:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    K = Scanner.int()
    ans = 0
    for i in range(1, K + 1):
        for j in range(1, K+1):
            for k in range(1, K + 1):
                g = Math.gcd(i, j)
                g = Math.gcd(g, k)
                ans += g

    print(ans)


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
k=int(input())
def solve(a,b):
	if a<b:
		if b%a==0:
			return a
		else:
			return solve(a,b%a)
	if a%b==0:
		return b
	else:
		return solve(b,a%b)
arr=[i+1 for i in range(k)]

l = [p for p in itertools.product(arr, repeat=3)]
s=0
dic={}
for i in l:
	a,b,c=i
	s+=solve(c,solve(a,b))
print(s)

Submission status: Time Limit Exceeded

Solution code:
import fractions
import itertools

K = int(input())
lis = list(range(1,K+1))
ans = 0

for team in itertools.product(lis, lis, lis):
    ans += fractions.gcd(fractions.gcd(team[0], team[1]), team[2])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
import itertools

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

K = int(input())
lis = list(range(1,K+1))
ans = 0

for team in itertools.product(lis, lis, lis):
    ans += gcd(*team)

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

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

print(sum_gcd)

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


N = int(input())

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

print(ans)

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

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())
#K = 200
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())
t = 0
for i1 in range(1, k+1):
    for i2 in range(1, k+1):
        for i3 in range(1, k+1):
            t+=math.gcd(math.gcd(i1, i2), i3)
print(t)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K = int(input())
#K = 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(a, b, c)

print(sum)

Submission status: Time Limit Exceeded

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

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:
import math
from functools import reduce
 
def gcd(*numbers):
  return reduce(math.gcd, numbers)
 
K = input('')
K=int(K)
la = lb = lc = list(range(1, K+1))
sum = 0
 
for a in range (len(la)):
  for b in range(len(lb)):
    for c in range(len(lc)):
      sum += gcd(la[a],lb[b],lc[c])
print(sum)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
dic = {}
def mygcd(x, y):
    if (x, y) in dic:
        return dic[(x, y)]
    if y == 0:
        dic[(x, y)] = x
        return x
    else:
        res = mygcd(y, x % y) #再帰定義
        dic[(x, y)] = res
        return res
ans = 0
for i in range(K, 0, -1):
    for j in range(K, 0, -1):
        tmp_gcd = mygcd(i, j)
        for k in range(K, 0, -1):
            ans += mygcd(tmp_gcd, k)
print(ans)

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)
def gcd2(a,b,c):
    return gcd(gcd(a,b),c)
counter=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):
            counter+=gcd2(i,j,k)
print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:


k = int(input())

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

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

def three_number_gcd(a, b, c):
    d = gcd(a, b)
    f = gcd(d, c)
    return f

for i in range(1, k+1):
    for m in range(1, k+1):
        for n in range(1, k+1):
            x = three_number_gcd(i,m,n)
            gcd_list.append(x)

print(sum(gcd_list))

Submission status: Time Limit Exceeded

Solution code:
import math

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

def three_number_gcd(a,b,c):
    d = math.gcd(a, b)
    f = math.gcd(d, c)
    return f

for i in range(1, k+1):
    for m in range(1, k+1):
        for n in range(1, k+1):
            x = three_number_gcd(i,m,n)
            gcd_list.append(x)

print(sum(gcd_list))

Submission status: Time Limit Exceeded

Solution code:
import math


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


k = int(input())
answer = 0
for w_a in range(1, k + 1):
    for w_b in range(1, k + 1):
        for w_c in range(1, k + 1):
            answer += gcd(w_a, w_b, w_c)

print(answer)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a, b):
    while b != 0 :
        t = a % b
        a = b
        b = t
    return a
        
sum = 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):
            sum = sum + gcd(gcd(a, b), c)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from numba import jit

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

@jit
def main2(K):
    ans = 0
    for i in range(1,K+1):
        for j in range(1,K+1):
            for k in range(1,K+1):
                ans += gcd(gcd(i,j),k)
    return ans    


K = int(input())
print(main2(K))

Submission status: Time Limit Exceeded

Solution code:
from numba import jit

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

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

N = int(input())
wa = 0
for i in range (1,N+1):
  for j in range (1,N+1):
    for h in range (1,N+1):
      wa += gcd(i,j,h) 
print(wa)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
def pgcd(x,y):
  while y>0:
    x,y=y,x%y
  return x
s = 0
for a in range(1,K+1):
  for b in range(1,K+1):
    for c in range(1,K+1):
      s+=pgcd(pgcd(a,b),c)
print(s)

Submission status: Time Limit Exceeded

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

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

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