#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <memory>

#define int long long

using namespace std;

int gcd(int a, int b) {
	if (a < b) swap(a, b);
	if (a % b == 0) return b;
	return gcd(a % b, b);
}

void Main()
{
	int k;
	cin >> k;

	int ans = 0;
	for (int a = 1; a <= k; a++) {
		for (int b = 1; b <= k; b++) {
			int gcd_ab = gcd(a, b);
			for (int c = 1; c <= k; c++) {
				ans += gcd(gcd_ab, c);
			}
		};
	}

	cout << ans << endl;
}

int32_t main()
{
	Main();
	return 0;
}

