#include <stdio.h>
#define MIN(x,y) (((x) > (y)) ? (y) : (x))
#define ABS(x) ((x) >= 0 ? (x) : (-(x)))

int gcd(int a, int b) {
  int tmp = 0;
  while (b != 0) {
    if (b < a) {
      tmp = a;
      a = b;
      b = tmp;
    }
    b = b % a;
  }
  return a;
}

int gcd3(int a, int b, int c) {
  return gcd(gcd(a, b), c);
}

int main() {
  int k;
  long long sum = 0;
  scanf("%d", &k);
  for (int a = 1; a <= k; a++) {
    for (int b = 1; b <= k; b++) {
      for (int c = 1; c <= k; c++) {
        sum += gcd3(a, b, c);
      }
    }
  }
  printf("%lld", sum);
  return 0;
}