#include <stdio.h>
int gcd(int p, int q) {
	while (q != 0) {
		int r = p % q;
		p = q;
		q = r;
	}
	return p;
}
int main(void) {
	int input =0;
	int num = 0;
	int output =0;

	scanf("%d", &input);
	for (int k = 1; k <= input; k++) {
		for (int i = 1; i <= input; i++) {
			for (int j = 1; j <= input; j++) {
				num = num + gcd(gcd(j, i), k);
			}
		}
	}

	output = num;
	printf("%d\n", output);
	return 0;
}