#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int gcm(int a, int b) {
	int tmp;
	if (b > a) {
		tmp = a;
		a = b;
		b = tmp;
	}
	while (1) {
		tmp = a % b;
		if (tmp ==0) {
			break;
		}
		else {
			a = b;
			b = tmp;
		}
	}

	return b;
}

int gcm(int a, int b, int c) {
	return gcm(gcm(a, b), c);
}

int main() {
	int i, j, k, n;
	long long sum = 0;
	cin >> n;
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			for (k = 1; k <= n; k++) {
				sum += gcm(i, j, k);
			}
		}
	}

	cout << sum << "\n";

	return 0;
}