Buggy python submission (verdict: Time Limit Exceeded):
class GCD:
    def __init__(self):
        self.numlist = dict()
        self.numlist2 = dict()
    def culc(self, K):
        ret = 0
        for i in range(1,K-1):
            for j in range(i+1, K):
                for k in range(j+1,K+1):
                    ret += self.gcd(i,j,k)*6
        
        for i in range(1,K+1):
            for j in range(1,K+1):
                if i != j:
                    ret += self.gcd(i,i,j) * 3
        for i in range(1, K+1):
            ret += self.gcd(i,i,i)

        return ret

    def gcd(self, a,b,c):
        l = [a,b,c]
        l.sort()
        l = tuple(l)
        if l in self.numlist:
            return self.numlist[l]
        else:
            temp_ = self.gcd_(l[0],l[1])
            temp_ = self.gcd_(temp_, l[2])
            self.numlist[l] = temp_
            return temp_

    def gcd_(self,a,b):
        l = (min(a,b), max(a,b))
        if l in self.numlist2:
            return self.numlist2[l]
        else:
            mod = max(a,b) % min(a,b)
            if mod == 0:
                ret = min(a,b)
                self.numlist2[l] = ret
                return ret
            else:
                ret = self.gcd_(min(a,b), mod)
                self.numlist2[l] = ret
                return ret

K = int(input())
gcd = GCD()
ret = gcd.culc(K)
print(ret)

Fixed submission:
class GCD:
    def __init__(self):
        self.numlist = dict()
    def culc(self, K):
        ret = 0
        
        for i in range(1,K):
            for j in range(i + 1,K+1):
                ret += self.gcd_(i,j) * 6

        for i in range(1,K-1):
            for j in range(i+1, K):
                for k in range(j+1,K+1):
                    ret += self.gcd(i,j,k)*6

        for i in range(1, K+1):
            ret += i

        return ret

    def gcd(self, a,b,c):
        #l = (a,b,c)
        #if l in self.numlist:
        #    return self.numlist[l]
        #else:
        temp_ = self.gcd_(a,b)
        temp_ = self.gcd_(temp_, c)
        
        return temp_

    def gcd_(self,a,b):
        l = (min(a,b), max(a,b))
        if l in self.numlist:
            return self.numlist[l]
        else:
            mod = max(a,b) % min(a,b)
            if mod == 0:
                ret = min(a,b)
                self.numlist[l] = ret
                return ret
            else:
                ret = self.gcd_(min(a,b), mod)
                self.numlist[l] = ret
                return ret

K = int(input())
gcd = GCD()
ret = gcd.culc(K)
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
class GCD:

    def culc(self, K):
        ret = 0
        self.numlist = dict()
        for i in range(1,K-1):
            for j in range(i+1, K):
                for k in range(j+1,K+1):
                    ret += self.gcd(i,j,k)*6
        
        for i in range(1,K+1):
            for j in range(1,K+1):
                if i != j:
                    ret += self.gcd(i,i,j) * 3
        for i in range(1, K+1):
            ret += self.gcd(i,i,i)

        return ret

    def gcd(self, a,b,c):
        l = [a,b,c]
        l.sort()
        l = tuple(l)
        if l in self.numlist:
            return self.numlist[l]
        else:
            temp_ = self.gcd_(l[0],l[1])
            temp_ = self.gcd_(temp_, l[2])
            self.numlist[l] = temp_
            return temp_

    def gcd_(self,a,b):
        mod = max(a,b) % min(a,b)
        if mod == 0:
            ret = min(a,b)
            return ret
        else:
            ret = self.gcd_(min(a,b), mod)
            return ret

K = int(input())
gcd = GCD()
ret = gcd.culc(K)
print(ret)

Fixed submission:
class GCD:
    def __init__(self):
        self.numlist = dict()
    def culc(self, K):
        ret = 0
        
        for i in range(1,K):
            for j in range(i + 1,K+1):
                ret += self.gcd_(i,j) * 6

        for i in range(1,K-1):
            for j in range(i+1, K):
                for k in range(j+1,K+1):
                    ret += self.gcd(i,j,k)*6

        for i in range(1, K+1):
            ret += i

        return ret

    def gcd(self, a,b,c):
        #l = (a,b,c)
        #if l in self.numlist:
        #    return self.numlist[l]
        #else:
        temp_ = self.gcd_(a,b)
        temp_ = self.gcd_(temp_, c)
        
        return temp_

    def gcd_(self,a,b):
        l = (min(a,b), max(a,b))
        if l in self.numlist:
            return self.numlist[l]
        else:
            mod = max(a,b) % min(a,b)
            if mod == 0:
                ret = min(a,b)
                self.numlist[l] = ret
                return ret
            else:
                ret = self.gcd_(min(a,b), mod)
                self.numlist[l] = ret
                return ret

K = int(input())
gcd = GCD()
ret = gcd.culc(K)
print(ret)

Buggy python submission (verdict: Runtime Error):
class GCD:

    def culc(self, K):
        ret = 0
        self.numlist = dict()
        for i in range(1,K+1):
            for j in range(1, K+1):
                for k in range(1,K+1):
                    ret += self.gcd(i,j,k)
        return ret

    def gcd(self, a,b,c):
        l = [a,b,c]
        l.sort()
        l = tuple(l)
        if l in self.numlist:
            return self.numlist[l]
        else:
            temp_ = self.gcd_(l[0],l[1])
            temp_ = self.gcd_(temp_, l[2])
            self.numlist[l] = temp_
            return temp_

    def gcd_(self,a,b):
        mod = max(a,b) % min(a,b)
        if mod == 0:
            ret = min(a,b)
            return ret
        else:
            self.gcd_(min(a,b), mod)

K = int(input())
gcd = GCD()
ret = gcd.culc(K)
print(ret)

Fixed submission:
class GCD:
    def __init__(self):
        self.numlist = dict()
    def culc(self, K):
        ret = 0
        
        for i in range(1,K):
            for j in range(i + 1,K+1):
                ret += self.gcd_(i,j) * 6

        for i in range(1,K-1):
            for j in range(i+1, K):
                for k in range(j+1,K+1):
                    ret += self.gcd(i,j,k)*6

        for i in range(1, K+1):
            ret += i

        return ret

    def gcd(self, a,b,c):
        #l = (a,b,c)
        #if l in self.numlist:
        #    return self.numlist[l]
        #else:
        temp_ = self.gcd_(a,b)
        temp_ = self.gcd_(temp_, c)
        
        return temp_

    def gcd_(self,a,b):
        l = (min(a,b), max(a,b))
        if l in self.numlist:
            return self.numlist[l]
        else:
            mod = max(a,b) % min(a,b)
            if mod == 0:
                ret = min(a,b)
                self.numlist[l] = ret
                return ret
            else:
                ret = self.gcd_(min(a,b), mod)
                self.numlist[l] = ret
                return ret

K = int(input())
gcd = GCD()
ret = gcd.culc(K)
print(ret)