#include <stdio.h>
long long gcd(long long gcd_a, long long gcd_b) {
	if (gcd_a < gcd_b) {
		long long gcd_c;
		gcd_c = gcd_a;
		gcd_a = gcd_b;
		gcd_b = gcd_c;
	}
	if (!gcd_b)return gcd_a;
	return gcd(gcd_b, gcd_a % gcd_b);
}
long long ans, n, x;
int main() {
	scanf("%lld", &n);
	for (long long i = 1; i <= n; i++) {
		for (long long j = 1; j <= n; j++) {
			x = gcd(i, j);
			for (long long k = 1; k <= n; k++) {
				ans += gcd(x, k);
			}
		}
	}
	printf("%lld\n", ans);
}