#include <stdio.h>

int gcd(int, int);

int main()
{
	int kk;
	long long int sum = 0;
	scanf("%d", &kk);
	for(int aa = 1;aa <= kk;aa++)
	{
		for(int bb = 1;bb <= kk;bb++)
		{
			for(int cc = 1;cc <= kk;cc++)
			{
				sum += gcd(cc, gcd(aa, bb));
			}
		}
	}
	printf("%lld\n", sum);
	return 0;
}

int gcd(int xx, int yy)
{
    int rr;
    while((rr = xx % yy) != 0)
    {
        xx = yy;
        yy = rr;
    }
    return yy;
}