#include <stdio.h>

int main() {
	int K, ans = 0;
	scanf("%d", &K);
	for (int i = 1; i <= K; i++) {
		for (int j = 1; j <= K; j++) {
			for (int l = 1; l <= K; l++) {
				int J = j, I = i, L = l,gc,gcd,N,n;
				//printf("%d %d %d ", I, J, L);
				if (I < J) {
					int t = I;
					I = J;
					J = t;
				}
				//printf("%d %d %d ", I, J, L);
				n = I % J;
				N = J;
				while (n != 0) {
					N = n;
					n = J % n;
					J = N;
				}
				gc = N;
				//printf("%d ", gc);

				if (gc < L) {
					int t = gc;
					gc = L;
					L = t;
				}
				n = gc % L;
				N = L;
				while (n != 0) {
					N = n;
					n = L % n;
					L = N;
				}
				gcd = N;
				//printf("%d\n",gcd);
				ans += gcd;
			}
		}
	}
	printf("%d", ans);
	return 0;
}