function Main(input) {
  const k = input;
  let sum = 0;

  const gcd = (a, b, c) => {
    max = Math.max(a, b, c);

    for (let i = 1; i <= max; i++) {
      if (max % i !== 0) {
        continue;
      }
      if (a % i === 0 && b % i === 0 && c % i === 0) {
        return i;
      }
    }
  }

  for (let a = 1; a <= k; a++) {
    for (let b = 1; b <= k; b++) {
      for (let c = 1; c <= k; c++) {
        sum += gcd(a, b, c);
      }
    }
  }

  console.log(sum);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));