#include <iostream>
using namespace std;

long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main(void) {
	int n, sum = 0;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			for (int k = 1; k <= n; ++k) {
				int a = gcd(i, j);
				sum += gcd(a, k);
			}
		}
	}
	cout << sum;
	return 0;
}