#include <stdio.h>
int gcd(int a,int b)
{
	int r;
	/* ユークリッドの互除法 */
	r = a % b;
	while( r != 0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int div(int a, int b, int c)
{
	int tmp;
	int d;

	if (a < b)
	{
		tmp = a;
		a = b;
		b = tmp;
	}
	d = gcd(a, b);
	if (c < d)
	{
		tmp = c;
		c = d;
		d = tmp;
	}
	return (gcd(c,d));
}

int		main(void)
{
	int k;
	scanf("%d", &k);
	int 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);
}
