#include<stdio.h>
int gcd(int a, int b)
{
	int r = a % b;
	while (r > 0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
int main()
{
	int k;
	scanf("%d", &k);
	int a, b, c;
	int ans = 0;
	for (a = 1; a <= k; a++)
		for (b = 1; b <= k; b++)
			for (c = 1; c <= k; c++)
				ans += gcd(a, gcd(b, c));
	printf("%d\n", ans);
	return 0;
}