#include <stdio.h>

int gcd(int a, int b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}

int tgcd(int a, int b, int c)
{
	return(gcd(gcd(a,b), c));
}

int main(void)
{
	int num;
	int k;
	int i,j,l;
	int hoge;

	scanf("%d", &k);
	num = 0;
	i = 1;
	while(i <= k)
	{
		j = 1;
		while(j <= k)
		{
			l = 1;
			while(l <= k)
			{
				num = num + tgcd(i, j, l);
				l++;
			}
			j++;
		}
		i++;
	}

	printf("%d\n", num);
	return (0);
}
