#include <bits/stdc++.h>

using namespace std;

template <class T> T gcd(T a, T b) {
	if (a < b) swap(a, b);
	while (b) {
		a = a % b;
		swap(a, b);
	}
	return a;
}

class Solution {
public:
	void solve() {
		int x;
		cin >> x;
		long long ans = 0;
		for (int i = 1; i <= x; i++) {
			for (int j = 1; j <= x; j++) {
				for (int k = 1; k <= x; k++) {
					ans += gcd(i, gcd(j, k));
				}
			}
		}
		cout << ans << "\n";

		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}