import "dart:io";

int gcd(int a, int b) {
  var temp = 0;
  var rem = 0;
  if (a < b) {
    temp = a;
    a = b;
    b = temp;
  }
  while (b > 0) {
    rem = a % b;
    if (rem == 0) {
      break;
    }
    a = b;
    b = rem;
  }
  return (b);
}

void main() {
  var k = int.parse(stdin.readLineSync()); 
  var sum = 0;
  for (int l = 0; l <= k; l++) {
    for (int m = 0; m <= k; m++) {
      for (int n = 0; n <= k; n++) {
        sum += gcd(gcd(l, m), n);
      }
    }
  }
  print(sum);
}