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


int main(){

  int N;
  scanf("%d",&N);

/*
  char A[];
  scanf("%s",A);
  */

  /*
  int A[N];
  int i;
  for(i=0;i<N;i++){
   scanf("%d",&A[i]);
   }
  */
  int A,B,C;
  long long int D;
  A = 0;
  B = 0;
  C = 0;
  D = 0;
  int i,j,k;
  for(i=1;i<=N;i++){
  for(j=1;j<=N;j++){
  for(k=1;k<=N;k++){
    A=i;
    B=j;
    C=k;
  int r;
  r =1;
  while(r != 0){
  r= A%B;
  A = B;
  if(r!=0){
  B = r;
  }
  }
  r =1;
while(r != 0){
  r= B%C;
  B = C;
  if(r!=0){
  C = r;
  }
  }
  D += C;
  }
  }
  }

  printf("%lld",D);


 return(0);
 }
