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: Wrong Answer

Solution code:
import math

gcd_sum = 0

for a in range(1,201):
    for b in range(1,201):
        ab = math.gcd(a,b)
        for c in range(1,201):
            gcd_sum += math.gcd(ab,c)       

print(gcd_sum)

Submission status: Wrong Answer

Solution code:
#C
import math
l=12
m=4
n=8
def gcd_great(l,m,n):
    p=math.gcd(l,m)
    q=math.gcd(p,n)
    return q

k=int(input())
gcd_list=[]
for h in range(1,k+1):
    for i in range(1,k+1):
        for j in range(1,k+1):
            gcd_num=gcd_great(h,i,j)
            gcd_list.append(gcd_num)
sum(gcd_list)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
K=int(input())
def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans = 0
for a in range(1, K+1):
    for b in range(1, a+1):
        for c in range(1, b+1):
            if a==b & b==c:
                ans += a
            else:
                ans += gcd(a,b,c)*3

print(ans)

Submission status: Wrong Answer

Solution code:
import math

K = int(input())

gcd = [[[0]* K for _ in range(K)] for _ in range(K)]

ans = 0
for a in range(K):
    for b in range(K):
        for c in range(K):
            if gcd[a][b][c] == 0:
                res = math.gcd(math.gcd(a,b),c)
                gcd[a][b][c] = res
                gcd[b][c][a] = res
                gcd[c][a][b] = res
                gcd[b][a][c] = res
                gcd[c][b][a] = res
                gcd[a][c][b] = res
                ans += res
            else:
                ans += gcd[a][b][c]

print(ans)

Submission status: Wrong Answer

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

ans = 0

for a in range(N):
  for b in range(N):
    for c in range(N):
      if a == 1 or b == 1 or c == 1:
        ans += 1  
      else:
        ans += math.gcd(a, math.gcd(b, c))
        
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input()) + 1


def gcd(a, b, c):
    maximum = max([a, b, c])
    max_gcd = 1

    for i in range(2, maximum + 1):
        if a % i == 0 and b % i == 0 and c % i == 0 and max_gcd < i:
            max_gcd = i

    return max_gcd


ans = 0
hash_table = {}
for a in range(1, N):
    for b in range(1, N):
        for c in range(1, N):
            if a == b == c:
                ans += a
                continue

            hash_name = ''.join(sorted([str(a), str(b), str(c)]))
            if hash_name in hash_table:
                cur = hash_table[hash_name]
            else:
                cur = gcd(a, b, c)
                hash_table['{}{}{}'.format(a, b, c)] = cur
            ans += cur

print(ans)

Submission status: Wrong Answer

Solution code:
import math
# math.gcd(x,y)

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

import itertools
h = itertools.combinations_with_replacement(list(range(1,N+1)), 3)

import math
from functools import reduce

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

ans = 0
for n1, n2, n3 in h:
  if n1 == n2 == n3:
    ans += gcd(n1,n2,n3)
  else:
    ans += gcd(n1,n2,n3)*3
print(ans)

Submission status: Wrong Answer

Solution code:
import math
k=int(input())
A=[[0 for i in range(k+1)] for j in range(k+1)]
s2=0
for i in range(1,k+1):
    for j in range(1,k+1):
        if i!=j:
            s2=s2+math.gcd(i,j)
            A[i][j]=math.gcd(i,j)
s1=0
for i in range(1,k-1):
    for j in range(i+1,k):
        for l in range(i+2,k+1):
            s1=s1+A[A[i][j]][l]

print(6*s1+3*s2+(k*(k+1))//2)

Submission status: Wrong Answer

Solution code:
import math

k = int(input())
sum = 0

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

Submission status: Wrong Answer

Solution code:
import math

K = int(input())

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

k = int(input())
ans = 0

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import functools

k = int(input())
sum = 0

for i in range(1, k+1):
  for j in range(1, k+1):
    for l in range(1, k+i):
      sum += functools.reduce(math.gcd, (i, j, l))
print(sum)

Submission status: Wrong Answer

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

if __name__ == '__main__':
    N = int(input())
    total = 0
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            for k in range(j + 1, N + 1):
                total += gcd(k, gcd(j, i))
    print(total)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
k=int(input())
count=0
for a in range(k):
  for b in range(k):
    for c in range(k):
      count+=gcd(gcd(a,b),c)
print(count)

Submission status: Wrong Answer

Solution code:
K = int(input())
def gcd(a,b,c):
  s = sorted([a,b,c])
  while s[1]%s[0]>0 and s[2]%s[0]>0:
    s[1] = s[1]%s[0]
    s[2] = s[2]%s[0]
    s = sorted(s)
  return s[0]

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

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

N = int(input())
i = 0

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

Submission status: Wrong Answer

Solution code:
a=str(input())
if '7' in a:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
K = int(input())
def gcd(x,y):
    if y == 0:return x
    return gcd(y,x%y)
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            if j < k:
                j,k = k,j
            temp = gcd(j,k)
            if i < temp:
                i,temp = temp,i
            ans += gcd(i,temp)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from math import sqrt
from collections import Counter, defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    s = input()
    for n in s:
        if n == "7":
            print("Yes")
            exit()
    print("No")
    pass


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush, heapify
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
from functools import reduce
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm_base(a, b):
    return (a * b) // gcd(a, b)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def main():
  k = int(input())
  ans = 0
  for a in range(1, k+1):
    for b in range(a, k+1):
      for c in range(b,k+1):
        if a==b and b==c:
          ans += gcd(gcd(a,b),c)
        else:
          ans += gcd(gcd(a,b),c) * 3
  print(ans)
  
  
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import math

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

k = int(input()) + 1
ans = 0
dp = {}
for a in range(1, k):
    for b in range(a, k):
        for c in range(b, k):
            if a == b and b == c:
                ans += a
            elif a == b or b == c:
                a, b = set((a, b, c))
                ans += math.gcd(a, b) * 3
            else:
                ans += gcd(a, b, c) * 6
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())

ans = 0
for i in range(1, N + 1):
    if i % 3 != 0 and i % 5 != 0:
        ans += i
print(ans)

Submission status: Wrong Answer

Solution code:
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):
            d = max([i, j, k])
            if i % d == 0 and j % d == 0 and k % d == 0:
                ans += d
            else:
                d -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
K = int(input())
ans1=0
ans2=0
ans3=0
ans = 0
for a in range(1,K-1):
    for b in range(a+1,K):
        for c in range(b+1,K+1):
            tmp = math.gcd(a,b)
            ans1 += math.gcd(c,tmp)

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

ans3 = sum(range(1,K+1))
print(ans1,ans2,ans3)
ans = ans1*6+ans2*3*2+ans3
print(ans)

Submission status: Wrong Answer

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


def gcd_count(i, j, k):
    s = min([i, j, k])
    a1 = i
    a2 = j
    a3 = k
    current = 1
    for m in range(s):
        if a1 % (m + 1) == 0 and a2 % (m + 1) == 0 and a3 % (m + 1) == 0:
            a1 = int(a1 / (m + 1))
            a2 = int(a2 / (m + 1))
            a3 = int(a3 / (m + 1))
            current = (m + 1) * current
    return current


for a in range(k):
    for b in range(k):
        for c in range(k):
            sum += gcd_count(a+1, b+1, c+1)

print(sum)

Submission status: Wrong Answer

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

for i in range(1,k+1):
    for j in range(i,k+1):
        for l in range(j,k+1):
            if i==j and j==l:
                ans+=i
                
            elif i==j:
                ans+=3*math.gcd(i,l)
                
            else:
                ans+=6*math.gcd(math.gcd(i,j),l)
                
                
            
print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd

n = int(input())
sum = 0
for i in range(1, n + 1):
    for j in range(1, i):
        for k in range(1, j):
            sum+=6*gcd(gcd(k,j),i)
        sum+=3*gcd(j,i)
    sum+=i
print(sum)

Submission status: Wrong Answer

Solution code:
import math

n=int(input())

sum = 0

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

print(sum)

Submission status: Wrong Answer

Solution code:
def gcd(x,y,z):
  p=[x,y,z]
  p.sort()
  a=p[0]
  b=p[1]
  while a!=0 and b!=0:
    b-=a
    if a>b:
      c=b
      b=a
      a=c
  if p[2]%b==0:
    return(b)
  else:
    return(1)
n=int(input())
s=0
for i in range(1,n+1):
  for j in range(1,n+1):
    for k in range(1,n+1):
      s+=gcd(i,j,k)
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

FizzBuzz = []

for i in range(N):
  if i%3==0 and i%5==0:
    pass
  elif i%3==0:
    pass
  elif i%5==0:
    pass
  else:
    FizzBuzz.append(i)

print(sum(FizzBuzz))

Submission status: Wrong Answer

Solution code:
import math
k = 200
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: Wrong Answer

Solution code:
import math
import math
from functools import reduce
#import itertools
#import statistics
#import numpy as np
#import collections
n = int(input())
#h  = list(map(int, input().split()))
#h, w = list(map(int, input().split()))

total = 0
for i in range(1, n+1):
    if i%3!=0 and i%5!=0:
        total += i

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

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(gcd(27, 18, 3))
print(ans)

Submission status: Wrong Answer

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

answer=0
for i in range(K):
  for j in range(K):
    gcd_ij=math.gcd(i,j)    
    for k in range(K):
      gcd_ijk=math.gcd(gcd_ij,k)
      answer+=gcd_ijk

print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import gcd
k = int(input())
gcdl = [[0 for i in range(k + 1)]for i in range(k+1)]
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcdl[i][j] = gcd(i, j)
s = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            s += gcdl[i][gcdl[j][k]]

print(s)

Submission status: Wrong Answer

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

k = int(input())

count = 0
from itertools import product
for a in range(1, k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            count += gcd(a, b, c)

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

K = int(input())
cnt = 0

for k_1 in range(K+1):
  for k_2 in range(K+1):
    for k_3 in range(K+1):
      cnt = cnt + gcd(k_1,k_2,k_3)

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

k = int(input())

memo = [[[None]*k for i in range(k)] for j in range(k)]

ans = 0
for p in range(k):
  for q in range(k):
    for r in range(k):
      a = sorted([p,q,r])
      if memo[a[0]][a[1]][a[2]] == None:
        memo[a[0]][a[1]][a[2]] = math.gcd(p,math.gcd(q,r))
      ans += memo[a[0]][a[1]][a[2]]
      
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import itertools
from functools import reduce


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


K = int(input())
GCD = 0
iterator = itertools.combinations_with_replacement(list(range(1, K+1)), 3)
for (a, b, c) in iterator:
    GCD += gcd(a, b, c)

print(GCD)

Submission status: Wrong Answer

Solution code:
import math

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

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

K = 2#int(input())

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

Submission status: Wrong Answer

Solution code:
import math
def main():
    #N,K,C=map(int,input().split())
    #A=list(map(int,input().split()))
    S=input()
    S=int(S)
    ans=0
    for i in range(S+1):
        for j in range(S+1):
            tmp=math.gcd(j,i)
            for k in range(S+1):
                ans+=math.gcd(k,tmp)
    #print()
    print(ans)
    

main()

Submission status: Wrong Answer

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

ans = 0

for i in range(K):
    for j in range(K):
        t = gcd(i, j)
        for k in range(K):
            ans += gcd(t, k)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from functools import lru_cache


@lru_cache(None)
def gcd(x, y):
    return x if y == 0 else gcd(y, y % x)


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

Submission status: Wrong Answer

Solution code:
import math
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

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

Submission status: Time Limit Exceeded

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

def gcd2(a,b): #互除法
  while True:
    mod = a % b
    if mod == 0:
      return b
    a = b
    b = mod

memo = {}
def gcd(a,b,c):
  a,b,c = sorted([a,b,c])
  if (a,b,c) not in memo:
    val = gcd2(gcd2(a,b), c)
    memo[(a,b,c)] = val
    return val
  return memo[(a,b,c)]

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

print(total)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce


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


total = 0
N = int(input())
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):
            total += gcd(x, k)

print(total)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce


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


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

print(total)

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

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

Submission status: Time Limit Exceeded

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

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

            sum_gcd += math.gcd(math.gcd(a,b) , c)

print(sum_gcd)

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

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

temp = []

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            temp.append(gcd(i,j,k))
print(sum(temp))

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())


ans = 0
for x in range(1,k+1):
    for y in range(1,k+1):
        for z in range(1,k+1):
            ans += math.gcd(math.gcd(x,y),z)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
ans = 0
def gcd(a,b):
    if a % b == 0:
        return b
    c = a % b
    return gcd(b,c)

for l in range(1,k+1):
    for m in range(1,k+1):
        for n in range(1,k+1):
            tmp = gcd(l,n)
            ans += gcd(tmp,m)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
y=int(input())
cnt=0
for i in range (1,y+1):
    for k in range(1,y+1):
        for j in range(1,y+1):
            a = [i,j,k]#リスト
            ans = a[0]
            for x in range(len(a)):
                ans = math.gcd(ans, a[x])
            cnt+=ans
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
def gcd1 (a, b):
    while True:
        if (a < b):
            a, b = b, a
        c = a%b
        if (c == 0):
            return (b)
        else:
            a = b
            b = c

def gcd2 (a, b, c):
    tmp = gcd1(a, b)
    ans = gcd1(tmp, c)
    return (ans)

count = 0
for i in range(k):
    for j in range(k):
        for l in range(k):
            tmp = gcd2(i + 1, j + 1, l + 1)
            count = count + tmp
print(count)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
from functools import reduce

def gcd2(*numbers):
    return reduce(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 += gcd2(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)

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

print(ans)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
from functools import reduce
K = int(input())
num = []
for i in range(1,K+1):
  num.append(i)
  
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

l = list(itertools.product(num, repeat=3))

ans = 0
for i in l:
  ans += gcd_list(i)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
def gcd(a,b):
    if b==0: return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,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(i,gcd(j,k))
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
K=int(input())
result=0
for a in range(1,K+1):
    for b in range(a+1,K+1):
        for c in range(b+1,K+1):
            result+=np.gcd.reduce([a,b,c])*6
    b=a
    for c in range(1,K+1):
        result+=np.gcd.reduce([a,c])*3
    result-=a*2
print(result)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
K=int(input())
result=0
for a in range(1,K+1):
    for b in range(a+1,K+1):
        for c in range(b+1,K+1):
            result+=np.gcd.reduce([a,b,c])*6
    b=a
    for c in range(1,K+1):
        result+=np.gcd.reduce([a,b,c])*3
    result-=a*2
print(result)

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

sum = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      #print ("gcd({} {} {} )".format(i,j,k))
      sum += gcd(i,j,k)
print (sum)

Submission status: Time Limit Exceeded

Solution code:

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

def main():
    ans = 0
    k = int(input())
    for i in range(k):
        for j in range(k):
            for l in range(k):
                ans += gcd(i+1,gcd(j+1,l+1))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

def gcd(a,b,c):
  s = [a,b,c]
  s.sort()
  a,b,c = s
  for n in range(1,a+1):
    if a % n == 0 and b % n == 0 and c % n == 0:
      yakusu = n
  return yakusu

total = 0

for x in range(1,k+1):
    for y in range(x,k+1):
        for z in range(y,k+1):
            if x == y == z:
                total += x
            elif x == y or y == z:
                total += 3 * gcd(x,y,z)
            else:
                total += 6 * gcd(x,y,z)

print(total)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

def gcd(a,b,c):
  s = [a,b,c]
  s.sort()
  a,b,c = s
  for n in range(1,a+1):
    if a % n == 0 and b % n == 0 and c % n == 0:
      yakusu = n
  return yakusu

total = 0
for x in range(1,k+1):
  for y in range(1,k+1):
    for z in range(1,k+1):
      total += gcd(x,y,z)
      
print(total)

Submission status: Time Limit Exceeded

Solution code:
# C - Sum of gcd of Tuples (Easy)
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(a,math.gcd(b,c))

print(s)

Submission status: Time Limit Exceeded

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

for i in range(1,K+1):
    for j in range(1,K+1):
        for m in range(1,K+1):
            c=math.gcd(i,j)
            b+=math.gcd(c,m)

print(b)

Submission status: Time Limit Exceeded

Solution code:
import math

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools

k=int(input())

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
from functools import reduce

def gcd_list(lis):
  return reduce(gcd, lis)

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_list([i,j,k])
      
print(ans)