#include <stdio.h>

int main(void) {
	int K;
	long sum = 0;
	int min;
	int tmp;
	
	scanf("%d", &K);
	
	for(int a = 1; a <= K; a++) {
		for(int b = 1; b <= K; b++) {
			for(int c = 1; c <= K; c++) {
				min = a;
				if( min > b ) min = b;
				if( min > c ) min = c;	
				
				for(int i = 1; i <= min; i++) {
					if( (a % i) != 0 )	continue;
					if( (b % i) != 0 )	continue;
					if( (c % i) != 0 )	continue;
					
					tmp = i;
				}
				
				sum += tmp;
			}
		}
	}
	
	printf("%ld\n", sum);
	
	return 0;
}
