#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
using namespace std;

int gcd(int a, int b, int c) {
	if (a > b) swap(a, b);
	while (b % a != 0) {
		int k = b % a;
		b = a;
		a = k;
	}
	if (a > c) swap(a, c);
	while (c % a != 0) {
		int k = c % a;
		c = a;
		a = k;
	}
	return a;
}
int main() {
	int k;
	int sum = 0;
	cin >> k;
	for (int i = 1;i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int l = 1;l <= k;l++) {
				sum += gcd(i, j, l);
			}
		}
	}
	cout << sum << endl;
}