#include<iostream>
using namespace std;
#include<cmath>
#include<algorithm>
#define int long long int
int32_t main()
{
	int k;
	cin>>k;
	int answer=0;
	int i,j,l;
	for(i=1;i<=k;i++)
	{
		for(j=1;j<=k;j++)
		{
			for(l=1;l<=k;l++)
			{
				int val=__gcd(i,__gcd(j,l));
				answer+=val;
			}
		}
	}
	cout<<answer<<endl;
}
