#include<stdio.h>

int main(void)
{
	unsigned long int a, b, c, d, e, r , s;
	int i, j, k, l;
	unsigned long long int sum = 0;
	int tmp;
	
	scanf("%ld", &a);

	for (i = 1; a >= i; i++) {
		for (j = 1; a >= j; j++) {

			b = i;
			c = j;

			if (b < c) {
				tmp = b;
				b = c;
				c = tmp;
			}

			r = b % c;
			while (r != 0) {
				b = c;
				c = r;
				r = b % c;
			}

			for (k = 1; a >= k; k++) {
				
				d = k;
				e = c;

				if (e < d) {
					tmp = e;
					e = d;
					d = tmp;
				}

				/* ユークリッドの互除法 */
				r = e % d;
				while (r != 0) {
					e = d;
					d = r;
					r = e % d;
				}

				sum = sum + d;

			}
		}
	}

	printf("%lld", sum);

	return 0;
}