#include <stdio.h>
int gc(int a, int b)
{
	int r, r2, tmp;
	if (a < b)
	{
		tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	r = a % b;
	while (r != 0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
	int gcd(int a, int b, int c)
	{
		int r,r2;
		r =gc(a, b);
		r2 = gc(r, c);
//		printf("%d %d %d -%d\n", a,b,c,r2);
		return r2;
	}
	int main(void)
	{
		int i, j, m;
		int cnt = 0, K;
		scanf("%d", &K);
		for (i = 1; i <= K; i++)
		{
			for (j = 1; j <= K; j++)
			{
				for (m = 1; m <= K; m++)
				{
					cnt += gcd(i, j, m);
				}
			}
		}
		printf("%d\n", cnt);
		return 0;
	}