#include <stdio.h>

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

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

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