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

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
int gcd3(int x, int y, int z) {
  int v = gcd(x,y);

  return gcd(v, z);
}

int main() {
    int n;
    int sum = 0;
    scanf("%d", &n);

for (int i = 1; i <= n; i++) {
  /* code */
  for (int j = 1; j <= n; j++) {
    /* code */
    for (int k = 1; k <= n; k++) {
      /* code */
      sum += gcd3(i,j,k);
      }
    }
  }

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

  return 0;
}