#include <stdio.h>

int div(int a, int b, int c)
{
	int max;
	int i = 1;
	int ans = 1;
	if (a < b)
		max = b;
	else
		max = a;
	if (max < c)
		max = c;
	while (i <= max)
	{
		if (a % i == 0 && b % i == 0 && c % i == 0)
		{
			ans = i;
		}
		i++;
	}
	return (ans);
}

int		main(void)
{
	long k;
	scanf("%ld", &k);
	long a,b,c;
	long sum = 0;
	a = 1;
	while (a <= k)
	{
		b = 1;
		while (b <= k)
		{
			c = 1;
			while (c <= k)
			{
				if (div(a,b,c))
					sum += div(a, b, c);
				c++;
			}
			b++;
		}
		a++;
	}
	printf("%ld", sum);
	return (0);
}