#include <stdio.h>

int main(int a, int b, int c){
  int min;
  min = a;
  if(min > b){
    min = b;
  }
  if(min > c){
    min = c;
  }
  
  return min;
}

int main(void){
  
  int k, a, b, c, sum = 0, min, gcd = 1, i;
  
  scanf("%d", &k);
  
  for(a = 1; a <= k; a++){
    for(b = 1; b <= k; b++){
      for(c = 1; c <= k; c++){
        min = find_min(a, b, c);
        for(i = 1; i < min; i++){
          if((a%i == 0) && (b%i == 0) && (c%i == 0)){
            gcd *= i;
          }
        }
        sum += gcd;
      }
    }
  }
  printf("%d", sum);
  
  return 0;
}