#include<iostream>
#include<string>
using namespace std;

int gcd(int a, int b)
{
	if (a%b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a%b));
	}
}

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