#include<stdio.h>
//#define scanf scanf_s
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}
int main()
{
	int n, i,j,k;
	long long sum=0;
	scanf("%d", &n);
	for (i = 1; i <= n; i++)
		for (j = 1; j <= n; j++)
			for (k = 1; k <= n; k++)
				sum += gcd(gcd(i, j), k);
	printf("%lld", sum);
}