#include <stdio.h>

void	ft_swap(int *x, int *y)
{
	int temp;

	temp = *x;
	*x = *y;
	*y = temp;
}

int		euclid(int small, int big)
{
	int amari = 0;

	if(small > big)
		ft_swap(&small, &big);
	while (1)
	{
		if((amari = big % small) == 0)
			return small;
		big = small;
		small = amari;
	}
	return (0);
}

int		main(void)
{
	int a = 0;
	int b;
	int c;
	int K;
	int ans = 0;
	int buff;

	scanf("%d", &K);
	while (++a <= K)
	{
		b = 0;
		while (++b <= K)
		{
			c= 0;
			while (++c <= K)
			{
				buff = euclid(a, b);
				ans = ans + euclid(buff, c);
			}
		}
	}
	printf("%d\n", ans);
	return (0);
}
