#include <iostream>

using namespace std;

int g[201][201][201];

int gcd(int a, int b);

int main()
{
	int k;
	cin >> k;

	long long ans = 0;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int l = 1; l <= k; l++) {
				ans += gcd(i, gcd(j, l));
			}
		}
	}
	cout << ans << endl;

	return 0;
}

int gcd(int a, int b)
{
	if (a < b) {
		int t = a;
		a = b;
		b = t;
	}

	int r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}
