#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep_b(i,n) for(int i=1;i<=(n);++i)

using namespace std;

int gcd(int n, int m)
{
	int r;
	if (n > m) {
		int t = m;
		m = n;
		n = t;
	}
	while ((r = m % n) != 0) {
		m = n;
		n = r;
	}
	return n;
}

int main()
{
	int N, a, b, c, sum = 0;
	cin >> N;
	rep_b(a, N)
		rep_b(b, N)
		rep_b(c, N)
	{
		sum += gcd(c, gcd(a, b));
	}
	cout << sum;
	return 0;
}