#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;
int gcd(int a, int b)
{
	if (b == 0)	return a;
	return gcd(b, a % b);
}
int main()
{
	int k;
	cin >> k;
	ll ans = 0;
	int ab;
	for (int a = 1; a <= k; ++a) {
		for (int b = 1; b <= k; ++b) {
			for (int c = 1; c <= k; ++c) {
				ab = gcd(a, b);
				ans += gcd(ab, c);
			}
		}
	}
	cout << ans << endl;
	return 0;
}