#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const LL INF = 1LL << 60;
int n, ans;

int main() {
	cin >> n;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			for(int k = 1; k <= n; k++) {
				int dd = __gcd(i, j);
				dd = __gcd(dd, k);
				ans += dd;
			}
		}
	}
	cout << ans << endl;
	return 0;
}