#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int gcd(int a, int b) {
	while (b > 0) {
		a %= b;
		swap(a, b);
	}

	return a;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int k;
	cin >> k;

	ll sum = 0;

	for (int a = 1; a <= k; a++) {
		for (int b = 1; b <= k; b++) {
			int t = gcd(a, b);
			for (int c = 1; c <= k; c++) {
				sum += gcd(t, c);
			}
		}
	}

	cout << sum;

	return 0;
}