# def gcd(a, b):
# 	while a != 0 and b != 0:
# 		if a >= b:
# 			remain = a % b
# 			a = remain
# 		else:
# 			remain = b % a
# 			b = remain
# 	if a >= b:
# 		return a
# 	else:
# 		return b 

import math

k = int(input())
sum = 0

for i in range(1, k+1):
	for j in range(1, i+1):
		for l in range(1, j+1):
			if i == j and j == l:
				sum += i
			elif i == j or j == l:
				a = math.gcd(i, j)
				b = math.gcd(j,l)
				g = math.gcd(a,b)
				sum += g*3

			else:
				a = math.gcd(i, j)
				b = math.gcd(j,l)
				g = math.gcd(a,b)
				sum += g*6

print(sum)
