import math

K=int(eval(input()))

print((sum(math.gcd(math.gcd(a,b),c) for a in range(1,K+1) for b in range(1,K+1) for c in range(1,K+1))))
import numpy as np

K=int(eval(input()))

k=np.arange(1,K+1)

print((np.sum(np.gcd.outer(np.gcd.outer(k,k),k))))
import math

K = int(eval(input()))
print(
    (
        sum(
            math.gcd(math.gcd(a, b), c)
            for a in range(1, K + 1)
            for b in range(1, K + 1)
            for c in range(1, K + 1)
        )
    )
)

import numpy as np

K = int(eval(input()))
k = np.arange(1, K + 1)
print((np.sum(np.gcd.outer(np.gcd.outer(k, k), k))))

-import math +import numpy as np -print( -    ( -        sum( -            math.gcd(math.gcd(a, b), c) -            for a in range(1, K + 1) -            for b in range(1, K + 1) -            for c in range(1, K + 1) -        ) -    ) -) +k = np.arange(1, K + 1) +print((np.sum(np.gcd.outer(np.gcd.outer(k, k), k))))