#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;

	return gcd(b, a%b);
}

int main()
{
	ll n,ans=0;
	string s;

	cin >> n;

	forll(i, 0, n)
	{
		forll(j, 0, n)
		{
			ll buf = gcd(max(i+1,j+1), min(i + 1,j + 1));

			forll(k, 0, n)
			{
				ans += gcd(max(buf, k + 1), min(buf, k + 1));
			}
		}
	}


	cout << ans << endl;

}