#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll gcd( ll a, ll b )
{
	ll c = a>b?a:b;
	ll d = a<b?a:b; 
	while(c%d)
	{
		ll e = c%d;
		c = d;
		d = e;
	}
	return d;
}
typedef long long ll;
int main()
{
	int k;
	cin>>k;
	ll sum = 0;
	for( int i=1; i<=k; i++ )
		for( int j=1; j<=k; j++ )
			for( int s=1;s<=k;s++)
				sum += gcd(i,gcd(j,s));
	cout << sum << endl;
	return 0;
}
