#include<stdio.h>

int gcb(int a, int b){
	int temp;
	if(a < b){
		temp = a;
		a = b;
		b = temp;
	}
	if(a % b == 0)
		return b;
	else
		return gcb(b, a % b);

}

int main(void){

	long SUM;
	int K, i, j ,l, t;
	scanf("%d", &K);

	SUM = 0;

	for(i = 1; i <= K;i++){
			for(j = 1; j <= K;j++){
					for(l = 1; l <= K;l++){
						t = gcb(i,j);
						SUM = SUM + gcb(t,l);
						
					}
			}
	}

	printf("%ld", SUM);
	return 0;
}