#include <stdio.h>

int min(int a, int b) {
  return a < b ? a : b;
}

int max(int a, int b) {
  return a > b ? a : b;
}

int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(max(a, b) % min(a, b), min(a, b));
}

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

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        int t = gcd(gcd(i, j), k);
        ans += t;
      }
    }
  }

  printf("%d\n", ans);
}
