#include<stdio.h>
#include<stdlib.h>

int gcd1(int a, int b){
  	int d;
  	if(b > a){
    	d = b;
        b = a;
        a = d;
    }
	if(a % b == 0){
    	return b;
    }else{
		return gcd1(b, a % b);
	}
}

int gcd2(int a, int b, int c){
	int d = gcd1(a, b);
    return gcd1(c, d);
}

int main(int argc, char** argv){
  	
  	int k;
  	scanf("%d", &k);
  	int sum = 0;

  	for(int i = 1; i <= k; i++){
    	for(int j = 1; j <= k; j++){
        	for(int l = 1; l <= k; l++){
            	sum += gcd2(i, j, l);
            }
        }
    }
  	printf("%d\n", sum);
	return 0;
}


