#include<stdio.h>
int gcd(int a,int b){
  int tmp;
  int r;
  
  if(a < b){
    tmp = a;
    a = b;
    b = tmp;
  }
  r = a % b;
  
  while(r != 0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main(void){
  int a,b,c;
  int input;
  unsigned int sum = 0;
  scanf("%d",&input);
  for(a = 1;a <= input;a++){
    for(b = 1;b <= input;b++){
      for(c = 1;c <= input;c++){
        sum += gcd(gcd(a,b),c);
      }
    }
  }
  printf("%u",sum);
  return 0;
}
    
