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

int gcd(int a, int b) {
  int r = 1;

  if (a < b) {
    int tmp = a;
    a = b;
    b = tmp;
  }

  while (r) {
    r = a % b;
    a = b;
    b = r;
  }

  return a;
}

int main(void) {
  int k;
  scanf("%d", &k);

  long long int sum = 0;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      for (int l = 1; l <= k; l++) {
        int tmp_gcd = gcd(i, j);
        sum += gcd(tmp_gcd, l);
        // printf("%lld\n", sum);
      }
    }
  }

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

  return 0;
}
