#include <stdio.h>
#include <stdlib.h>

int euclid( int a, int b)
{
	int temp;
	if (a < b)
	{
		temp = a; a = b; b = temp;
	}
	if (b < 1)
	{
		return -1;
	}
	if (a % b == 0)
		return b;

	return euclid(b, a % b);
}

int main(void)
{
	char buf[4];
	char *str;
	int a, b, c, k, sum;
	int tmp;
	int count = 0;
	a = b = c = sum = 0;

	if (scanf("%3s", buf) != 1)
	{
		return 1;
	};
	str = buf;
	k = atoi(buf);
	for (a = 1; a <= k; a++)
	{
		for (b = 1; b <= k; b++)
		{
			for (c = 1; c <= k; c++)
			{
				tmp = euclid(a, b);
				tmp = euclid(tmp, c);
				sum += tmp;
			}
		}
	}
	printf("%d\n", sum);
	return (0);
}
