#include <stdio.h>
 
int gcd(int num1, int num2, int num3){
  	int sma_num;
  
	if((num1 - num2) < 0 && (num1 - num3) < 0){
    	sma_num = num1;
    } else if ((num2 - num3) < 0){
    	sma_num = num2;
    } else {
    	sma_num = num3;
    }
  
  	for(int i = sma_num; i >= 0; i--){
    	if((num1 % i) == 0 && (num2 % i) == 0 && (num3 % i) == 0){
        	return i;
        } else {
        	continue;
        }
    }
}
 
int main(void){
  	int k, result;
  	int sum = 0;
  
	scanf("%d", &k);
  
  	for(int a = 1; a <= k; a++){
    	for(int b = 1; b <= k; b++){
        	for(int c = 1; c <= k; c++){
  				result = gcd(a, b, c);
              	sum += result;
            }
        }
    }
  
  printf("%d", sum);
}