import sys
import math
#sys.exit()
#sorted( ,reverse=True)
N = int(input())
#S,T = map(int, input().split())
#A = list(map(int, input().split()))
#print(N)
#print(S,T)
#print(A)
ans = 0
for i in range (1,N+1):
    for j in range (1,N+1):
        for k in range (1,N+1):
            ans += math.gcd(math.gcd(i,j),math.gcd(j,k))
            
print(ans)
