import math
from functools import reduce

a=int(input())
b=[]
for i in range(1,a+1):
    for j in range(1,a+1):
        for n in range(1,a+1):
            c=reduce(math.gcd,[i,j,n])
            b.append(c)

print(sum(b))
