#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

int gcd(int a,int b){ return b? gcd(b,a%b): a;}

int main(void)
{
	int n;
	scanf("%d",&n);
	ll ans=0;
	for(int i=1; i<=n; ++i)
		for(int j=1; j<=n; ++j)
		{
			int tmp = gcd(i,j);
			for(int k=1; k<=n; ++k)
				ans += gcd(tmp,k);
		}
	printf("%lld",ans);
	return 0;
}