from itertools import combinations_with_replacement
from functools import reduce
import math

def gcd(numbers):
    return reduce(math.gcd, numbers)

K = int(input())
GCD = [ k for k in range(1, K+1)]
output = []

for v in combinations_with_replacement(GCD, 3):
    if len(set(v))==2:
        bi = 3
    elif len(set(v))==3:
        bi = 6
    else:
        bi = 1
    output.append(gcd(list(v))*bi)
print(sum(output))
