K = int(input())
ans1 = 0
ans2 = 0
ans3 = 0

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def gn(num):
    value = num[0]
    for item in num[1:]:
        value = gcd(value, item)
    return value


a = gn([3,15,18])

import itertools

seq = [x+1 for x in range(K)]
ptr = list(itertools.combinations(seq,3))

for i in range(len(ptr)):
    ans1 += gn(ptr[i])*6
    
seq2 = [x+1 for x in range(K)]
ptr2 = list(itertools.combinations(seq2,2))

for i in range(len(ptr2)):
    ans2 += gcd(ptr2[i][0],ptr2[i][1])*6
    
ans3 = K*(K+1)/2
print(int(ans1+ans2+ans3))