Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

total = 0
# 3つ同じ
for i in range(K):
  total += i+1

# 2つ同じ
#for i in range(0,K-1):
#  total += 6*(K-1-i)*(i+1)

total += 6*(K-1)	# １つが必ず1の場合

for i in range(1,K-1):
  for j in range(i+1,K):
    tmp = 0
    for k in range(1,i+2):
      if (i+1)%k == 0 and (j+1)%k == 0:
        tmp = k
    total += tmp*6

# バラバラ
total += int(6*(K-1)*(K-2)/2)	# １つが必ず1の場合
for i in range(1,K-2):
  for j in range(i+1,K-1):
    for k in range(j+1,K):
      if (j+1)%(i+1) == 0 and (k+1)%(i+1) == 0:
        total += (i+1)*6
      else:
        tmp = 0
        for l in range(1,i+1):
          if (i+1)%l == 0 and (j+1)%l == 0 and (k+1)%l == 0:
            tmp = l
        total += tmp*6
print(total)
  


Fixed submission:
K = int(input())

total = 0
for i in range(1,K+1,1):
  for j in range(1,K+1,1):
    tmp1 = i
    tmp2 = j
    while tmp1 % tmp2 != 0:
      tmp = tmp1 % tmp2
      tmp1 = tmp2
      tmp2 = tmp
    for k in range(1,K+1,1):
      tmp1 = k
      tmp3 = tmp2
      while tmp1 % tmp3 != 0:
        tmp = tmp1 % tmp3
        tmp1 = tmp3
        tmp3 = tmp
      total += tmp3
print(total)

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

total = 0
# 3つ同じ
for i in range(K):
  total += i+1

# 2つ同じ
total += 6*(K-1)
for i in range(1,K-1):
  for j in range(i+1,K):
    tmp = 0
    for k in range(1,i+2):
      if (i+1)%k == 0 and (j+1)%k == 0:
        tmp = k
    total += tmp*6

# バラバラ
total += int(6*(K-1)*(K-2)/2)
for i in range(1,K-2):
  for j in range(i+1,K-1):
    for k in range(j+1,K):
      if (j+1)%(i+1) == 0 and (k+1)%(i+1) == 0:
        total += (i+1)*6
      else:
        tmp = 0
        for l in range(1,i+1):
          if (i+1)%l == 0 and (j+1)%l == 0 and (k+1)%l == 0:
            tmp = l
        total += tmp*6
print(total)
  


Fixed submission:
K = int(input())

total = 0
for i in range(1,K+1,1):
  for j in range(1,K+1,1):
    tmp1 = i
    tmp2 = j
    while tmp1 % tmp2 != 0:
      tmp = tmp1 % tmp2
      tmp1 = tmp2
      tmp2 = tmp
    for k in range(1,K+1,1):
      tmp1 = k
      tmp3 = tmp2
      while tmp1 % tmp3 != 0:
        tmp = tmp1 % tmp3
        tmp1 = tmp3
        tmp3 = tmp
      total += tmp3
print(total)

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

total = 0
# 3つ同じ
for i in range(K):
  total += i+1

# 2つ同じ
for i in range(K-1):
  for j in range(i+1,K):
    if i+1 == 1:
      total += 1*6
    elif (j+1)%(i+1)==0:
      total += (i+1)*6
    else:
      tmp = 0
      for k in range(1,i+1):
        if (i+1)%k == 0 and (j+1)%k == 0:
          tmp = k
      total += tmp*6

# バラバラ
for i in range(K-2):
  for j in range(i+1,K-1):
    for k in range(j+1,K):
      if i+1 == 1:
        total += 1*6
      elif (j+1)%(i+1) == 0 and (k+1)%(i+1) == 0:
        total += (i+1)*6
      else:
        tmp = 0
        for l in range(1,i+1):
          if (i+1)%l == 0 and (j+1)%l == 0 and (k+1)%l == 0:
            tmp = l
        total += tmp*6
print(total)
  

Fixed submission:
K = int(input())

total = 0
for i in range(1,K+1,1):
  for j in range(1,K+1,1):
    tmp1 = i
    tmp2 = j
    while tmp1 % tmp2 != 0:
      tmp = tmp1 % tmp2
      tmp1 = tmp2
      tmp2 = tmp
    for k in range(1,K+1,1):
      tmp1 = k
      tmp3 = tmp2
      while tmp1 % tmp3 != 0:
        tmp = tmp1 % tmp3
        tmp1 = tmp3
        tmp3 = tmp
      total += tmp3
print(total)