#include <iostream>
#include <cstdio>

using namespace std;

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

int ans = 0, K;

int main() {
	scanf("%d", &K);
	for (int a = 1; a <= K; a++) {
		for (int b = 1; b <= K; b++) {
			for (int c = 1; c <= K; c++) {
				ans += gcd(a, gcd(b, c));
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}