#include <stdio.h>
int gcd(int a,int b){
	int r;
	int temp;
	if(b > a){
		temp = a;
		a = b;
		b = temp;}
	r = a % b;
	while(r > 0){
		a = b;
		b = r;
		r = a % b;
		}
	return r;
}
int main(void){
	int a,b,c;
	int k;
	int sum = 0;
	scanf("%d",&k);
	for(a = 1;a < k+1 ;a++){
		for (b = 1;b < k+1;b++){
			for (c = 1;c < k+1;c++){
				sum += gcd((gcd(a,b)),c);
						}
					}
				}
	printf("%d",sum);
	return 0;
}	