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


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

	int64_t sum =0;
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=n; j++) {
			for (int l=1; l<=n; l++) {
				int g = gcd(j, l);
				sum += gcd(i, g);
			}
		}
	}

	cout << sum << endl;

}
