#include<stdio.h>

int main() {
	int l, a, b, c, r, t, sum = 0;
	scanf("%d", &l);
	for (int i = 1; i <= l; i++) {
		for (int j = 1; j <= l; j++) {
			for (int k = 1; k <= l; k++) {
				a = i;
				b = j;
				c = k;
				if (a < b) {
					t = a;
					a = b;
					b = t;
				}
				r = a%b;
				while (r != 0) {
						a = b;
						b = r;
						r = a%b;
				}
				if (b < c) {
						t = b;
						b = c;
						c = t;
				}
				r = b%c;
				while (r != 0) {
					b = c;
					c = r;
					r = b%c;
				}
				sum = sum + c;
			}
		}
	}
	printf("%d", sum);
}