def my_gcd(p, q):
    if p < q:
        tmp = q
        q = p
        p = tmp
    r = p % q
    while r > 0:
        p = q
        q = r
        r = p % q
    return q

k = int(input())
gcd_list = [[my_gcd(m + 1, n + 1) for n in range(k)] for m in range(k)]
sum = 0
for a in range(k):
    for b in  range(k):
        for c in range(k):
            sum += gcd_list[a][gcd_list[b][c] - 1]
print(sum)