def gcd(p, q):
    while (q != 0):
        r = p % q
        p = q
        q = r
    return p
K = int(input())
cnt = 0
for a in range(K):
    for b in range(K):
        for c in range(K):
            g1 = 0
            g2 = 0
            g1 = gcd(a+1, b+1)
            g2 = gcd(g1, c+1)
            cnt += g2
print(str(cnt))