#include<stdio.h>

int s(int a, int b) {
	int  r, 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 main(void)
{
	int a,b,c,K;
	int i, j, k;
	long long int ans = 0;
	scanf("%d", &K);
	for (i = 1; i <= K;i++) {
		for (j = 1;j <= K;j++) {
			for (k = 1;k <= K;k++) {
				ans += s(s(i,j),k);
			}
		}

	}
	printf("%lld", ans);

	return 0;
}