Buggy python submission (verdict: Time Limit Exceeded):
import math

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


ans = 0
for a in range(1, k + 1):
    if a == 1:
        ans += k * k
    else:
       for b in range(1, k + 1):
            if b == 1:
               ans += k
            else:
                for c in range(1, k + 1):
                    if c == 1:
                        ans += 1
                    else:
                        if a == b:
                            ans += math.gcd(a, c)
                        elif a == c:
                            ans += math.gcd(b, c)
                        else:
                            tmp = math.gcd(a, b)
                            ans += math.gcd(tmp, c)

print(ans)

Fixed submission:
import math

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


ans = 0
for a in range(1, k + 1):
    if a == 1:
        ans += k * k
    else:
       for b in range(1, k + 1):
            if b == 1:
               ans += k
            else:
                if a == b:
                    tmp = a
                    if tmp == 1:
                        ans += k
                    else:
                        for c in range(1, k + 1):
                            if c == 1:
                                ans += 1
                            else:
                                ans += math.gcd(tmp, c)
                else:
                    tmp = math.gcd(a, b)
                    if tmp == 1:
                        ans += k
                    else:
                        for c in range(1, k + 1):
                            if c == 1:
                                ans += 1
                            else:
                                ans += math.gcd(tmp, c)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

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

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

ans = 0
for a in range(1, k + 1):
    if a == 1:
        ans += k * k
    else:
       for b in range(1, k + 1):
            if b == 1:
               ans += k
            else:
                for c in range(1, k + 1):
                    if c == 1:
                        ans += 1
                    else:
                        ans += gcd([a, b, c])

print(ans)

Fixed submission:
import math

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


ans = 0
for a in range(1, k + 1):
    if a == 1:
        ans += k * k
    else:
       for b in range(1, k + 1):
            if b == 1:
               ans += k
            else:
                if a == b:
                    tmp = a
                    if tmp == 1:
                        ans += k
                    else:
                        for c in range(1, k + 1):
                            if c == 1:
                                ans += 1
                            else:
                                ans += math.gcd(tmp, c)
                else:
                    tmp = math.gcd(a, b)
                    if tmp == 1:
                        ans += k
                    else:
                        for c in range(1, k + 1):
                            if c == 1:
                                ans += 1
                            else:
                                ans += math.gcd(tmp, c)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

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

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

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)

Fixed submission:
import math

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


ans = 0
for a in range(1, k + 1):
    if a == 1:
        ans += k * k
    else:
       for b in range(1, k + 1):
            if b == 1:
               ans += k
            else:
                if a == b:
                    tmp = a
                    if tmp == 1:
                        ans += k
                    else:
                        for c in range(1, k + 1):
                            if c == 1:
                                ans += 1
                            else:
                                ans += math.gcd(tmp, c)
                else:
                    tmp = math.gcd(a, b)
                    if tmp == 1:
                        ans += k
                    else:
                        for c in range(1, k + 1):
                            if c == 1:
                                ans += 1
                            else:
                                ans += math.gcd(tmp, c)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
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)

Fixed submission:
import math

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


ans = 0
for a in range(1, k + 1):
    if a == 1:
        ans += k * k
    else:
       for b in range(1, k + 1):
            if b == 1:
               ans += k
            else:
                if a == b:
                    tmp = a
                    if tmp == 1:
                        ans += k
                    else:
                        for c in range(1, k + 1):
                            if c == 1:
                                ans += 1
                            else:
                                ans += math.gcd(tmp, c)
                else:
                    tmp = math.gcd(a, b)
                    if tmp == 1:
                        ans += k
                    else:
                        for c in range(1, k + 1):
                            if c == 1:
                                ans += 1
                            else:
                                ans += math.gcd(tmp, c)

print(ans)