#include<bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define sz(v) (int) v.size()
#define all(v) v.begin(), v.end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int MAX_K = 205;

int gcd[MAX_K][MAX_K];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int k;
	cin >> k;
	for (int a = 1; a <= k; ++a) {
		for (int b = 1; b <= k; ++b) {
			gcd[a][b] = __gcd(a, b);
		}
	}
	ll ans = 0;
	for (int a = 1; a <= k; ++a) {
		for (int b = 1; b <= k; ++b) {
			for (int c = 1; c <= k; ++c) {
				ans += gcd[a][gcd[b][c]];
			}
		}
	}
	cout << ans << "\n";
	return 0;
}