#include <stdio.h>

int main(void) {

	int k, sum = 0, a, b, c, x, y, r;

	scanf("%d", &k);

	for (a = 1; a <= k; a++)
		for (b = 1; b <= k; b++)
			for (c = 1; c <= k; c++) {

				if (a>b) {
					x = a;
					y = b;
				}
				else {
					x = b;
					y = a;
				}

				r = x % y;
				while (r != 0) {
					x = y;
					y = r;
					r = x % y;
				}

				if (y>c) {
					x = y;
					y = c;
				}
				else {
					x = c;
				}

				r = x % y;
				while (r != 0) {
					x = y;
					y = r;
					r = x % y;
				}
				sum += y;
			}
	printf("%d", sum);

	return 0;
}