
#include <iostream>
#include<map>
#include<vector>
#include<algorithm>
#include <stdio.h>
#include<set>
#include<string>
#include<math.h>
#include<cmath>
#include<iomanip>
#include<queue>
#include<stack>
#define ll long long
using namespace std;
long double pi = 3.14159265358979323846;
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

int g(int n1, int n2) {
	if (n2 != 0)
		return g(n2, n1 % n2);
	else
		return n1;
}

int gcd(int a, int b, int c) {

	return g(g(a, b), c);
}

int main()
{
	int n;  cin >> n;
	ll sum = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			for (int k = 1; k <= n; k++)
				if (i == j && j == k)
					sum += i;
				else
					sum += gcd(i, j, k);
	cout << sum;
	return 0;
}