#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
typedef long long ll; 

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } 

int main() {FIN
	
	ll i, j, k, t, n, sum = 0;
	cin >> n;
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			t = gcd(i, j);
			for (k = 1; k <= n; k++)
				sum += gcd(t, k);
		}
	}
	cout << sum << "\n";
	return 0;
}
