#include <stdio.h>

long GCD(long a, long b){
  long dividend, divisor;
  if (a >= b) {
    dividend = a;
    divisor = b;
  } else {
    dividend = b;
    divisor = a;
  }
  long remainder;
  while (1) {
    if (divisor == 1) {
      return 1;
    }
    remainder = dividend % divisor;
    if (remainder == 0) {
      break;
    } else {
      dividend = divisor;
      divisor = remainder;
    }
  }
  return divisor;
}

int main(void){

  long k;
  scanf("%ld", &k);
  long sum;
  long sum_a = 0;
  long sum_b = 0;
  long sum_c = 0;
  for (long i = 1; i <= k; i++) {
    for (long j = i+1; j <= k; j++) {
      for (long l = j+1; l <= k; l++) {
        sum_a += GCD(i,GCD(j,l));
      }
    }
  }
  for (long i = 1; i <= k; i++) {
    for (long j = i+1; j <= k; j++) {
      sum_b += GCD(i,j);
    }
  }
  for (long i = 1; i <= k; i++) {
    sum_c += i;
  }
  sum = sum_a*6 + sum_b*6 + sum_c;

  printf("%ld\n", sum);

  return 0;
}