#include <stdio.h>
#include <stdlib.h>

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

int main (void) {
	int a, b, c, k, sum = 0;
	scanf("%d", &k);
	for (c = 1; c <= k; c++) {
		for (b = 1; b <= k; b++) {
			for (a = 1; a <= k; a++) {
				sum += gcd(gcd(a, b), c);
			}
		}
	}
	printf("%d\n", sum);
	return 0;
}