#include<stdio.h>
int gcd(int x, int y)
{
	int t,r;
	if(x==0)
		return x;
	if(y==0)
		return y;
	if(x<y)
	{
		t = x;
		x = y;
		y = t;
	}
	do{
		r = x%y;
		if(r){
			x = y;
			y = r;
		}
	}while(r);
	return y;
}
int main()
{
	int K,i=1,j=1,k=1;
	long long sum=0;
	scanf("%d",&K);
	for(i=1;i<=K;i++)
		for(j=1;j<=K;j++)
			for(k=1;k<=K;k++)
				sum+=gcd(gcd(i,j),k);
	printf("%lld",sum);
}