#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;

int		gcd(int a, int b);
int		gcdr(int a, int b);

int		main(void){
	int k;
	cin >> k;
	int a, b, c;
	a = 1;
	int		gcdt;
	int		sum;

	sum = 0;
	while (a <= k)
	{
		b = 1;
		while (b <= k)
		{
			gcdt = gcd(a, b);
			c = 1;
			while (c <= k)
			{
				sum += gcd(gcdt, c);
				c++;
			}
			b++;
		}
		a++;
	}		
	cout << sum << endl;
}

int		gcd(int a, int b)
{
	if (a < b)
		return (gcdr(b, a));
	return (gcdr(a, b));
}

int		gcdr(int a, int b)
{
	if (!b)
		return (a);
	return (gcdr(b, a % b));
}
