Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# atcoder 
# Türkçe konuşyorum
# Türkler var mı?
# memnün oldum
import sys
import math


sys.setrecursionlimit(10 ** 8)

#def divmin
#for i in range(d, 1, -1):
#    if(d % i == 0):
#        print(i)
def pgcd(a, b):
    while b!=0:
        a,b=b,a%b
    return a

def msum(a, b, c):
    if (a <= b) and (a <= c): 
        return math.gcd(a, math.gcd(b,c))
        #while(a >= 1):
        #    if (b % a == 0) and (c % a == 0):
        #        return a
            
    elif (b <= a) and (b <= c):
        return(math.gcd(b, math.gcd(a,c)))
    elif (c <= a) and (c <= b):
        return math.gcd(c, math.gcd(a,b))
    else:
        print("Grande érreur dans ta tête!!!")

def çözmek(num):
    csum = 0
    for i in range(1, num+1):
        for j in range(1, num+1):
            for l in range(1, num+1):
                #print(i,j,l)
                #csum += msum(i,j,l)
                csum += pgcd(i, pgcd(j,l))

    return csum


if __name__ == "__main__":
    K = int(input())
    print(çözmek(K))


Fixed submission:
#!/usr/bin/env python3
# atcoder 
# Türkçe konuşyorum
# Türkler var mı?
# memnün oldum
import sys
import math


sys.setrecursionlimit(10 ** 8)

#def divmin
#for i in range(d, 1, -1):
#    if(d % i == 0):
#        print(i)
def pgcd(a, b):
    while b!=0:
        a,b=b,a%b
    return a

def msum(a, b, c):
    if (a <= b) and (a <= c): 
        return math.gcd(a, math.gcd(b,c))
        #while(a >= 1):
        #    if (b % a == 0) and (c % a == 0):
        #        return a
            
    elif (b <= a) and (b <= c):
        return(math.gcd(b, math.gcd(a,c)))
    elif (c <= a) and (c <= b):
        return math.gcd(c, math.gcd(a,b))
    else:
        print("Grande érreur dans ta tête!!!")

def çözmek(num):
    csum = 0
    for i in range(1, num+1):
        for j in range(1, num+1):
            for l in range(1, num+1):
                #print(i,j,l)
                #csum += msum(i,j,l)
                csum += math.gcd(i, math.gcd(j,l))

    return csum


if __name__ == "__main__":
    K = int(input())
    print(çözmek(K))

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# atcoder 
# Türkçe konuşyorum
# Türkler var mı?
# memnün oldum
import sys
import math


sys.setrecursionlimit(10 ** 8)

#def divmin
#for i in range(d, 1, -1):
#    if(d % i == 0):
#        print(i)
def pgcd(a, b):
    while b!=0:
        a,b=b,a%b
    return a

def msum(a, b, c):
    if (a <= b) and (a <= c): 
        return math.gcd(a, math.gcd(b,c))
        #while(a >= 1):
        #    if (b % a == 0) and (c % a == 0):
        #        return a
            
    elif (b <= a) and (b <= c):
        return(math.gcd(b, math.gcd(a,c)))
    elif (c <= a) and (c <= b):
        return math.gcd(c, math.gcd(a,b))
    else:
        print("Grande érreur dans ta tête!!!")

def çözmek(num):
    csum = 0
    for i in range(1, num+1):
        for j in range(1, num+1):
            for l in range(1, num+1):
                #print(i,j,l)
                csum += msum(i,j,l)


    return csum


if __name__ == "__main__":
    K = int(input())
    print(çözmek(K))


Fixed submission:
#!/usr/bin/env python3
# atcoder 
# Türkçe konuşyorum
# Türkler var mı?
# memnün oldum
import sys
import math


sys.setrecursionlimit(10 ** 8)

#def divmin
#for i in range(d, 1, -1):
#    if(d % i == 0):
#        print(i)
def pgcd(a, b):
    while b!=0:
        a,b=b,a%b
    return a

def msum(a, b, c):
    if (a <= b) and (a <= c): 
        return math.gcd(a, math.gcd(b,c))
        #while(a >= 1):
        #    if (b % a == 0) and (c % a == 0):
        #        return a
            
    elif (b <= a) and (b <= c):
        return(math.gcd(b, math.gcd(a,c)))
    elif (c <= a) and (c <= b):
        return math.gcd(c, math.gcd(a,b))
    else:
        print("Grande érreur dans ta tête!!!")

def çözmek(num):
    csum = 0
    for i in range(1, num+1):
        for j in range(1, num+1):
            for l in range(1, num+1):
                #print(i,j,l)
                #csum += msum(i,j,l)
                csum += math.gcd(i, math.gcd(j,l))

    return csum


if __name__ == "__main__":
    K = int(input())
    print(çözmek(K))