#include <stdio.h>
#include <inttypes.h>

int gcd(int a, int b) {
	while (b > 0) {
		int r = a % b;
		a = b;
		b = r;
	}
	return a;
}

int main(void) {
	int K;
	int a, b, c;
	uint64_t kotae = 0;
	if (scanf("%d", &K) != 1) return 1;
	for (a = 1; a <= K; a++) {
		for (b = 1; b <= K; b++) {
			int mofu = gcd(a, b);
			for (c = 1; c <= K; c++) {
				kotae += gcd(mofu, c);
			}
		}
	}
	printf("%" PRIu64 "\n", kotae);
	return 0;
}
