from itertools import combinations
import fractions
n = int(input())
ans = 0
for r in range(1,4): 
    if r>n:
        break
    for x  in combinations([x+1 for x in range(n)],r):
        if len(x)==1:
            ans += x[0]
        elif len(x)==2:
            ans += fractions.gcd(x[0],x[1])*6
        else:
            tmp = fractions.gcd(x[0],x[1])
            ans += fractions.gcd(x[2],tmp)*6