import std.stdio;

int gcd(int a, int b) {
	int gcd_(int x, int y) {
		if (y == 0) return x;
		return gcd_(y, x % y);
	}
	if (a > b) return gcd_(a, b);
	return gcd_(b, a);
}

void main() {
	int count;
	readf(" %s", &count);

	long sum;
	foreach (i;0..count) {
		foreach (j;0..count) {
			auto ij = gcd(i + 1, j + 1);
			foreach (k;0..count) {
				sum += gcd(ij, k + 1);
			}
		}
	}

	writeln(sum);
}
