#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <math.h>


int ASC(const void *a, const void *b) {
	return *(int *)b - *(int *)a;//降順
}
int GCD(int a, int b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main(void)
{
	int a, b, c, n;
	int ans = 0;
	scanf("%d",&n);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= n; k++) {
				a = GCD(i, j);
				//printf("%d %d = %d\n", i, j,a);
				b = GCD(a,k);
				//printf("%d %d\n",a,b);
				ans += b;
			}
		}
	}
	printf("%d", ans);
	return 0;
}