#include<stdio.h>

int getgcd(int n, int m)
{
	int r;
	if (n > m) {
		int t = m;
		m = n;
		n = t;
	}
	while ((r = m % n) != 0) {
		m = n;
		n = r;
	}
	return n;
}

int main()
{
	int k, i, j, l;
	int gcd, sum;

	scanf("%d", &k);
	for (i = 1;i <= k;i++) {
		for (j = 1;j <= k;j++) {
			for (l = 1;l <= k;l++) {
				gcd = getgcd(getgcd(i, j), l);
				sum = sum + gcd;
			}
		}
	}
	printf("%d", sum);

	return 0;
}