#include <stdio.h>

int gcd_two(int n, int m) {
  if(m == 0) return n;
  return gcd_two(m, n % m);
}

int gcd_three(int l, int m, int n) {
  return gcd_two(gcd_two(l, m), n);
}

int main(void) {
  int count;
  int i, j, k;
  long sum = 0;
  scanf("%d", &count);
  for(i = 1;i <= count;i++) {
    for(j = 1;j <= count;j++) {
      for(k = 1;k <= count;k++) {
        sum += gcd_three(i, j, k);
      }
    }
  }
  printf("%ld\n", sum);
  return 0;
}
