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

int gcd_euclid(int u, int v) {
  int r;
  while (0 != v) {
    r = u % v; u = v; v = r; /* swap */
  }
  return u;
}

int main(void){
    int a,b,c,K,i,j,k,ans;
    int sum = 0;

	scanf("%d",&K);

	for(i=1; i<=K; i++){
		for(j=1; j<=K; j++){
			for(k=1; k<=K; k++){
				ans = gcd_euclid(gcd_euclid(i,j),k);
				sum += ans;
			}
		}
	}
	
	printf("%d",sum);
	
    return 0;
}