#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#pragma warning(disable : 4996) //_CRT_SECURE_NO_WARNINGS

int gcd(int a, int b) {
	int temp;
	if (a < b) {
		temp = b;
		b = a;
		a = temp;
	}
	if (a % b == 0) {
		return b;
	}
	else {
		gcd(b, a % b);
	}
	gcd(b, a % b);
}

int main(void) {
	int k = 0;
	int sum = 0;
	scanf("%d", &k);
	for (int i = 1;i <= k;i++) {
		for (int j = 1;j <= k;j++) {
			int A = gcd(i, j);
			for (int l = 1;l <= k;l++) {
				sum += gcd(A, l);
			}
		}
	}
	printf("%d", sum);
	return 0;
}