import "dart:io";

void main(List<String> args) {
  int k = int.parse(stdin.readLineSync());
  List<List<int>> gcds = [];
  int sum = 0;

  for (int i1 = 1; i1 <= k; i1++) {
    for (int i2 = 1; i2 <= k; i2++) {
      for (int i3 = 1; i3 <= k; i3++) {
        gcds.add([i1, i2, i3]);
      }
    }
  }

  gcds.forEach((List<int> nums) {
    sum += gcd(nums);
  });

  print(sum);
}

int gcd (List<int> nums) {
  int tmp = nums[0];

  for (int i = 1; i < nums.length; i++) {
    tmp = tmp.gcd(nums[i]);
  }

  return tmp;
}