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
from fractions import gcd
input = sys.stdin.readline

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

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


print(res)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

if __name__ == "__main__":
    X = 0
    K = int(input())

    for i in range(1,K + 1):
        for j in range(1, K + 1):
            for l in range(1, K + 1):
                X += gcd(i, j, l)

    print(X)

Submission status: Time Limit Exceeded

Solution code:
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)



def main():
    K = int(input()) + 1
    ans = 0
    for i in range(1, K):
        for j in range(1, K):
            for k in range(1, K):
                gcd = 1
                mx = min(i, j, k)
                for l in range(2, K):
                    if i % l == 0 and j % l == 0 and k % l == 0:
                        gcd = l
                    if l == mx:
                        break
                ans += gcd
    print(ans)

main()

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


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


k = int(input())
l = []
res = 0

for i in range(k):
    for j in range(i, k):
        for m in range(j, k):
            l.append([i+1, j+1, m+1])


for i in range(len(l)):
    # print(l[i])
    if l[i][0] == l[i][1] and l[i][1] == l[i][2]:
        # print("1通り")
        # print(gcd(l[i]))
        res += gcd(l[i])
    elif l[i][0] == l[i][1] or l[i][1] == l[i][2] or l[i][0] == l[i][2]:
        # print("3通り")
        # print(gcd(l[i]))
        res += gcd(l[i])*3
    else:
        # print("6通り")
        # print(gcd(l[i]))
        res += gcd(l[i])*6

print(res)

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 l in range(1, K + 1):
    for m in range(1, K + 1):
        for n in range(1, K + 1):
            ans += gcd(l, m, n)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
from itertools import *
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 product([i for i in range(1,K+1)], repeat = 3):
  ans += gcd(i[0],i[1],i[2])
print(ans)

Submission status: Time Limit Exceeded

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

def gcd(a, b):
    if(a > b):
        a, b = b, a

    while(b > 0):
        r = a % b
        a = b
        b = r

    return a


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


print(total)

Submission status: Time Limit Exceeded

Solution code:
# AtCoder Beginner Contest 162: C (2020/04/12)
import math
K = int(input())
S = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            x = [a, b, c]
            ans = x[0]
            for i in range(1, 3):
                ans = math.gcd(ans, x[i])
            S = S + ans
print(S)

Submission status: Time Limit Exceeded

Solution code:

K = int(input())

import math
from functools import reduce

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

dammy = []
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            dammy.append(gcd(a, b, c))

print(sum(dammy))

Submission status: Time Limit Exceeded

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

K = int(input())
Klist = [i+1 for i in range(K)]
total = 0
for a in Klist:
  for b in Klist:
    for c in Klist:
      total += gcd(gcd(a, b), c)
print(total)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
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 += reduce(math.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)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
    
n=int(input())
ans=0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    K = INT()

    gcdf = lambda *numbers: reduce(gcd, numbers)
    ans = 0
    for i in range(K):
        for j in range(K):
            for k in range(K):
                ans += gcdf(i + 1, j + 1, k + 1)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


input_num = int(input()) + 1
result = 0
for a in range(1, input_num):
  for b in range(1, input_num):
    for c in range(1, input_num):
      result += np.gcd.reduce([a, b, c])
print(result)

Submission status: Time Limit Exceeded

Solution code:
import sys
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),math.gcd(j,k))
            
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from math import gcd

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):
            a = [i, j, k]
            count += reduce(gcd, a)
print(count)

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:
k = int(input())
from fractions import gcd
from functools import reduce

x = 0
for a in range(1, k+1):
  for b in range(1, k+1):
    for c in range(1, k+1):
      x += reduce(gcd, [a,b,c])
      
print(x)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
answer=0

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

K=int(input())
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            #print(i,j,k)
            answer+=gcd(i,j,k)
                
                
print(answer)

Submission status: Time Limit Exceeded

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

def gcd_three(a, b, c):
    r = math.gcd(a, b)
    if( r == 1 ):
        return 1
    else:
        return math.gcd(r, c)
sum = 0

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

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:
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 a in range(1,200+1):
  for b in range(1, 200+1):
    for c in range(1, 200+1):
      ans += gcd(a,b,c) 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
def gcd(a, b, c):
    gcd1 = 1
    for i in range(2, c+1):
        if a%i == 0 and b%i == 0 and c%i == 0:
            gcd1 = i
    # print(gcd1)
    return gcd1

sum_gcd = 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:
                sum_gcd += gcd(a, b, c)
            elif a == b or b == c or c == a:
                sum_gcd += 3*gcd(a, b, c)
            else:
                sum_gcd += 6*gcd(a, b, c)
print(sum_gcd)

Submission status: Time Limit Exceeded

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

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


main()

Submission status: Time Limit Exceeded

Solution code:
import math
def gcd(a, b, c):
    x = math.gcd(a, b)
    return(math.gcd(x, c))

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
import sys
input = sys.stdin.readline  # 改行コード「\n」を呼んでしまうため、文字数など、注意！！


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

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

# print(gcd(100,20,10))

k = int(input().replace("\n",""))
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())
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:
#x,y,z = list(map(int,input().split()))
# k = int(input())

import numpy as np

k = int(input())
ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for kk in range(1,k+1):
            if i == j == kk:
                ans += i
                continue
            ans += np.gcd(np.gcd(i,j),kk)            

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:
def gcd(a,b):
	if(a==0):
		return b
	return gcd(b % a,a)
n=int(input())
sum1=0
for i in range(1,n+1):
	for j in range(1,n+1):
		for k in range(1,n+1):
			gcd1=gcd(i,j)
			gcd2=gcd(gcd1,k)
			sum1+=gcd2
print(sum1)

Submission status: Time Limit Exceeded

Solution code:
import math


def list_gcd(A):
    """N個の最大公約数
    Args:
        A (list[int])

    Returns:
        int: 最大公約数

    Examples:
        >>> list_gcd([1300, 34, 54, 60])
        2
    """
    ans = A[0]
    for i in range(1, len(A)):
        ans = math.gcd(ans, A[i])
    return ans


def resolve():
    K = int(input())

    ans = 0

    for kk in range(1, K+ 1):
        for jj in range(1, K+ 1):
            for ii in range(1, K+ 1):
                ans += list_gcd([kk, jj, ii])

    print(ans)


resolve()

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

print(ans)

Submission status: Time Limit Exceeded

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

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 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 fractions
n=int(input())
ans=0
for i in range(1,n+1):
    for j in range(i,n+1):
        g=fractions.gcd(i,j)
        for k in range(j,n+1):
            l=fractions.gcd(g,k)
            if i==j and j==k:
                ans+=l
            elif i==j or j==k or k==i:
                ans+=3*l
            else:
                ans+=6*l
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


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


sum_N = 0
for i in range(1, N + 1):
    for j in range(1, N + 1):
        for k in range(1, N + 1):
            sum_N += gcd(i, j, k)

print(sum_N)

Submission status: Time Limit Exceeded

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

def Main(N):
    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)
    return ans
    

def main():
    N = int(input())
    print(Main(N))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def gcd(m, n):
    if n == 0:
        return m
    else:
        return gcd(n, m % n)

K = int(input())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from functools import lru_cache

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


@lru_cache(maxsize=None)
def solve(x, y):
    return math.gcd(x, y)


def main():
    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):
                x = [i, j, k]
                x.sort()
                xx = solve(x[0], x[1])
                if xx > x[2]:
                    ans += solve(x[2], xx)
                else:
                    ans += solve(xx, x[2])

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

import math
k = inn()
sm = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for m in range(1,k+1):
            sm += math.gcd(math.gcd(i,j),m)
print(sm)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

n = int(input())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

import math
from functools import reduce

# 標準入力 <int>
N = int(input())

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

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

Submission status: Time Limit Exceeded

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

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 l in range(1,k+1):
            ans += gcd(i,j,l)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

k = int(input().rstrip())

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

a = list(range(1, k + 1))
b = list(range(1, k + 1))
c = list(range(1, k + 1))

ans = 0
for i in a:
    for j in b:
        for k in c:
            ans += gcd([i, j, k])

print(ans)

Submission status: Time Limit Exceeded

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

print(g)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
n = int(input())
ans = 0


def gcd(n, m):
    a, b = n, m
    if a > b:
        a, b = b, a
    while a != 0:
        a, b = b % a, a
    return b


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

Submission status: Time Limit Exceeded

Solution code:
K=int(input())

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

ans=0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#problem C
import math
input_d31 = input()
K = int(input_d31)

gcd = 0

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

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

def gcd(nums):
    while True:
        gcd = 30000
        min_idx = -1
        c = 0
        for i in range(3):
            if 0 < nums[i] < gcd:
                gcd = nums[i]
                min_idx = i
        for i in range(3):
            nums[i] %= gcd
            if nums[i] > 0: c += 1
        if c == 0:
            return gcd
        else:
            nums[min_idx] = gcd

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


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


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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

def gcd (a,b):
  if a < b: a, b = b, a
  while b:
    a,b = b, a % b
  return a
print (sum([gcd(gcd(x,y),z) for x in range(1,N+1)  for y in range(1,N+1)  for z in range(1,N+1)]))

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
#a,b = map(int,input().split())
#a_L = list(map(int,input().split()))

import math
from functools import reduce

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

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

ans = 0
dic = {}
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            tmp = [a,b,c]
            tmp = list(sorted(tmp))
            moji = list(map(str,tmp))
            moji = " ".join(moji)
            try:
                dic[moji]
                ans += dic[moji]
            except:
                num = gcd(tmp[0],tmp[1],tmp[2])
                ans += num
                dic[moji] = num


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

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

print(sum_ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
from itertools import combinations

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

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

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

Submission status: Time Limit Exceeded

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

result = 0
for k in range(1, K + 1):
  for l in range(1, K + 1):
    for m in range(1, K + 1):
      gcd_kl = fractions.gcd(k, l)
      gcd_klm = fractions.gcd(gcd_kl, m)
      result += gcd_klm

print(result)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
def gcd(a, b, c):
    z = min(a, b, c)
    for i in range(z, 0, -1):
        if a%i==0 and b%i==0 and c%i==0:
            return i

k = int(input())

d = {}

totsum = 0
for config in list(product(range(1, k+1), range(1, k+1), range(1, k+1))):
    a, b, c = config

    if tuple(sorted((a, b, c))) in d:
        ans = d[tuple(sorted((a, b, c)))]
    else: 
        ans = gcd(a, b, c)
        d[tuple(sorted((a, b, c)))] = ans

    totsum += ans

print(totsum)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

k = int(input())

a = 0

for i in range(1, k + 1):
    for l in range(1, k + 1):
        for m in range(1, k + 1):
            a += np.gcd.reduce([i, l, m])
print(a)

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

n = int(input())

gcd_dic = {}
ans = 0
for i in range(1, n + 1):
    for j in range(1, n + 1):
        for k in range(1, n + 1):
            fs = frozenset({i, j, k})
            if fs not in gcd_dic:
                gcd_dic[fs] = gcd(gcd(i, j), k)
            ans += gcd_dic[fs]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    

import math
from functools import reduce

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

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

cnt=0
k=int(input())

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

print(cnt)

Submission status: Time Limit Exceeded

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import sys
sys.setrecursionlimit(10000)
from functools import lru_cache

@lru_cache(maxsize=100000)
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

@lru_cache(maxsize=100000)
def gcd3(a,b,c):
   return gcd(gcd(a,b),c)

n = int(stdin.readline().rstrip())

sum = 0

for i in range(n):
    for j in range(n):
        for k in range(n):
            a,b,c = sorted((i+1,j+1,k+1))
            sum += gcd3(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 = int(input())
sum = 0

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

print(sum)

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

Submission status: Time Limit Exceeded

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

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


if __name__ == "__main__":

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

Submission status: Time Limit Exceeded

Solution code:
g = [[0 for i in range(250)] for j in range(250)]


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

import math
ans = 0

for a in r:
    for b in r:
        for c in r:

            if g[a][b] > 0:
                ab = g[a][b]
            else:
                ab = g[a][b] = math.gcd(a, b)
            if g[ab][c] > 0:
                ab = g[ab][c]
            else:
                ab = g[ab][c] = math.gcd(ab, c)
            ans += ab

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import math
# 1行だけ読むやつ

N = int(stdin.readline().rstrip().split()[0])
Sum = 0

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

print(Sum)

Submission status: Time Limit Exceeded

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

def gcd(*numbers):
    return reduce(math.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:
K = int(input())

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

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

ans = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
def calc_gcd2(a, b):
    if b == 0:
        return a
    else:
        return calc_gcd2(b, a % b)
    
def calc_gcd3(a, b, c):
    gcd_ab = calc_gcd2(a, b)
    return calc_gcd2(gcd_ab, c)
    
K = int(input())
tanget_num = range(1, K+1)
sum_ = 0
for i in tanget_num:
    for j in tanget_num:
        for k in tanget_num:
            sum_ = sum_ + calc_gcd3(i, j, k)
print(str(sum_))

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b):
    if a < b:
        a, b = b, a
    q = a // b
    r = a - q * b
    if r == 0:
        return b
    else:
        return gcd(b,r)

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