#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n;
long long ans;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
	 for (int j=1;j<=n;++j)
	 {
	 	int now=__gcd(i,j);
	 	if (now==1) ans+=n;
	 	else
	 	{
	 		for (int k=1;k<=n;++k) ans+=__gcd(now,k);
	 	}
	 }
	printf("%lld\n",ans);
return 0;
}