library calculate;

import "dart:io";
part "../libs/calculate.dart";

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);
}