#include<iostream>
#include<vector>
#include<string>
#include<sstream>
#include<chrono>
#include<algorithm>
#include<functional>
#include<cstdlib>
#include<numeric>
#include<queue>
#include<stack>
using namespace std;
typedef unsigned long long ull;
int main()
{

	int k = 0;
	cin >> k;
	ull sum = 0;
	for (int a = 1; a <= k; a++)
		for (int b = 1; b <= k; b++)
			for (int c = 1; c <= k; c++)
				sum += std::gcd(std::gcd(a, b), c);

	std::cout << sum << std::endl;

}