#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 1e2+5;
int GCD(int x, int y)
{
	return (y ? GCD(y, x % y) : x);
}
int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n;
	cin >> n;
	int gcd[n+1][n+1];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			gcd[i][j] = GCD(i, j);
	ll ans = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			for (int k = 1; k <= n; k++)
				ans += gcd[i][gcd[j][k]];
	cout << ans;
	return 0;
}
