#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>
#include <queue>
#include <stack>

using namespace std;

int gcd(int a, int b, int c) {
	int v[3] = { a,b,c }, mini = 200;
	while (1) {
		v[1] %= v[0];
		v[2] %= v[0];
		mini = min(mini, min(v[1], v[2]));
		sort(v, v + 3);
		if (v[0] == 0 && v[1] == 0)break;
		if (v[0] == 0) {
			swap(v[0], v[1]);
			swap(v[1], v[2]);
		}
	}
	return v[2];
}

int main() {
	int k;
	cin >> k;
	int sum = 0;
	for (int i = 1; i <= k; i++) {
		for (int j = i; j <= k; j++) {
			for (int l = j; l <= k; l++) {
				if (i == j && j == l)sum += gcd(i, j, l);
				else if (i != j && j != l && l != i)sum += (gcd(i, j, l) * 6);
				else sum += (gcd(i, j, l) * 3);
			}
		}
	}
	cout << sum << endl;
	return 0;
}

