#include<stdio.h>
int gdc(int i, int j, int k) {

	int c = 0;
	int tmp = 0;

	/*iが大きくなるように並び替える*/
	if (i < j) {

		tmp = i;
		i = j;
		j = tmp;
	}

	c = i % j;
	/*iとjの最大公約数を求める*/

	while (c > 0) {

		i = j;

		j = c;
		c = i % j;

	}



	/*i,jの最大公約数jと,kから、これらの最大公約数を求める*/

	/*kの方が大きければ入れ替える*/
	if (j < k) {

		tmp = j;
		j = k;
		k = tmp;


	}

	int d = j % k;


	while (d > 0) {

		j=k;
		k = d;
		d= j%k;

	}

	

	return k;
}


int main(void) {

	int i = 0;
	int j = 0;
	int k = 0;
	int n = 0;

	int c = 0;
	int sum = 0;



	scanf("%d", &n);

	for (i = 1; i <= n; i++) {

		for (j = 1; j <= n; j++) {

			for (k = 1; k <= n; k++) {


				c = gdc(i, j, k);

				printf("%d\n", c);
				sum = sum + c;



			}


		}

	}


	printf("答えは%d", sum);
	return 0;


}
