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

int gcd(int x,int y,int z){
  int tmp = z;
  while( x % y != 0 ){
     z = x % y;
     x = y;
     y = z;
  }
  x = tmp;

  while( x % y != 0 ){
     z = x % y;
     x = y;
     y = z;
  }
  return y;
}
int main(void){
  int N =0;
  long sum=0;
  scanf("%d\n",&N);
  for(int i=1;i < (N+1);i++){
    for(int j =1;j < (N+1);j++){
      for(int k =1;k< (N+1);k++){
        sum += gcd(i,j,k);
      }
    }
  }
  printf("%ld\n",sum);
  return 0;
}