#include<stdio.h>

int gcd(int x, int y);

int main() {
	int n;
	int x, y, z;
	scanf("%d", &n);
	int t, s, q;
	s = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= n; k++) {
				t = gcd(i, j);
				q = gcd(t, k);

				s += q;
			}
		}
	}
	printf("%d", s);

}
int gcd(int x, int y) {
	int t;
	t = x >= y ? x : y;
	if (x != t) {

		t = x;
		x = y;
		y = t;
	}

	while (x % y) {
		t = x % y;
		x = y;
		y = t;

	}
	return y;
}
