import math
from functools import reduce

def calc(a, b, c):
    return reduce(math.gcd, [a, b, c])

def solve(k):
    count = 0
    for i in range(1, k+1):
        for j in range(1, k+1):
            for k in range(1, k+1):
                count += calc(i, j, k)

    return count

k = int(input())

print(solve(k))
