K=io.read()

function gcd(a,b)
    if b ~= 0 then
        return gcd(b, a % b)
    else
        return a
    end
end

X={}
for i=1,K do
    X[i] = {}
end

for i=1,K do
    for j=1,K do
        X[i][j] = gcd(i,j)
    end
end

sum = 0
for i=1,K do
    for j=1,K do
        for k=1, K do
            sum = sum + gcd(X[i][j],k)
        end
    end
end
print(sum)