Buggy python submission (verdict: Runtime Error):
import math as np
K=int(input())
s=0
d=0
for a in range(1,K+1):
    if a%2==0:
        for b in range(2,K+1,2):
            if a>b:
                if a%b==0:
                    d=b
                else:
                    d=np.gcd(a%b,b)
            if a<b:
                if b%a==0:
                    d=a
                else:
                    d=np.gcd(b%a,a)
            if a==b:
                d=a
            for c in range(2,K+1,2):
                if c>d:
                    if c%d==0:
                        s+=d
                    else:
                        s+=np.gcd(c%d,d)
                if c<d:
                    if d%c==0:
                        s+=c
                    else:
                        s+=np.gcd(d%c,c)
                if c==d:
                    s+=c
    if a%2==1:
        for b in range(1,K+1,2):
            if a>b:
                if a%b==0:
                    d=b
                else:
                    d=np.gcd(a%b,b)
            if a<b:
                if b%a==0:
                    d=a
                else:
                    d=np.gcd(b%a,a)
            if a==b:
                d=a
            for c in range(1,K+1,2):
                if c>d:
                    if c%d==0:
                        s+=d
                    else:
                        s+=np.gcd(c%d,d)
                if c<d:
                    if d%c==0:
                        s+=c
                    else:
                        s+=np.gcd(d%c,c)
                if c==d:
                    s+=c
    if K%2==0:
        s+=K**3-(K//2)**3-(k//2+1)**3
    else:
        s+=K**3-(K//2)**3-(k//2)**3
print(s)


Fixed submission:
import numpy as np
K=int(input())
s3=0
s2=0
s1=0
s0=0
for a in range(1,K-1):
    for b in range(a+1,K):
        d=np.gcd(a,b)
        for c in range(b+1,K+1):
            s0+=np.gcd(c,d)
for a in range(1,K):
    for c in range(a+1,K+1):
        s1+=np.gcd(a,c)
for a in range(1,K):
    for b in range(a+1,K+1):
        s3+=np.gcd(a,b)
for k in range(K+1):
    s2+=k
print(s0*6+s1*3+s3*3+s2)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
K=int(input())
s=0
d=0
for a in range(1,K+1):
    for b in range(1,K+1):
        if a>b:
            if a%b==0:
                d=b
            else:
                d=np.gcd(a%b,b)
        if a<b:
            if b%a==0:
                d=a
            else:
                d=np.gcd(b%a,a)
        if a==b:
            d=a
        for c in range(1,K+1):
            if c>d:
                if c%d==0:
                    s+=d
                else:
                    s+=np.gcd(c%d,d)
            if c<d:
                if d%c==0:
                    s+=c
                else:
                    s+=np.gcd(d%c,c)
            if c==d:
                s+=c
print(s)


Fixed submission:
import numpy as np
K=int(input())
s3=0
s2=0
s1=0
s0=0
for a in range(1,K-1):
    for b in range(a+1,K):
        d=np.gcd(a,b)
        for c in range(b+1,K+1):
            s0+=np.gcd(c,d)
for a in range(1,K):
    for c in range(a+1,K+1):
        s1+=np.gcd(a,c)
for a in range(1,K):
    for b in range(a+1,K+1):
        s3+=np.gcd(a,b)
for k in range(K+1):
    s2+=k
print(s0*6+s1*3+s3*3+s2)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
K=int(input())
s=0
for a in range(1,K+1):
    for b in range(1,K+1):
        d=np.gcd(a,b)
        for c in range(1,K+1):
            s+=np.gcd(c,d)
print(s)


Fixed submission:
import numpy as np
K=int(input())
s3=0
s2=0
s1=0
s0=0
for a in range(1,K-1):
    for b in range(a+1,K):
        d=np.gcd(a,b)
        for c in range(b+1,K+1):
            s0+=np.gcd(c,d)
for a in range(1,K):
    for c in range(a+1,K+1):
        s1+=np.gcd(a,c)
for a in range(1,K):
    for b in range(a+1,K+1):
        s3+=np.gcd(a,b)
for k in range(K+1):
    s2+=k
print(s0*6+s1*3+s3*3+s2)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
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+=np.gcd(a,np.gcd(b,c))
print(s)


Fixed submission:
import numpy as np
K=int(input())
s3=0
s2=0
s1=0
s0=0
for a in range(1,K-1):
    for b in range(a+1,K):
        d=np.gcd(a,b)
        for c in range(b+1,K+1):
            s0+=np.gcd(c,d)
for a in range(1,K):
    for c in range(a+1,K+1):
        s1+=np.gcd(a,c)
for a in range(1,K):
    for b in range(a+1,K+1):
        s3+=np.gcd(a,b)
for k in range(K+1):
    s2+=k
print(s0*6+s1*3+s3*3+s2)