const fs = require("fs");
const buffer = fs.readFileSync(0); // STDIN_FILENO = 0
const K = parseInt(buffer.toString());


function* combinations(elements, length) {
  for (let i = 0; i < elements.length; i++) {
    if (length === 1) {
      yield [elements[i]];
    } else {
      let remaining = combinations(elements.slice(i, elements.length), length - 1);
      for (let next of remaining) {
        yield [elements[i], ...next];
      }
    }
  };
}


function gcd(a, b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}

function solve(K) {
  const numbers = Array(K).fill().map((_, i) => i + 1)
  const combs = Array.from(combinations(numbers, 3));
  let result = 0;
  for (let comb of combs) {
    if (comb[0] === comb[1] && comb[1] === comb[2]) {
      result += comb[0]
    } else if(comb[0] === comb[1] || comb[1] === comb[2]) {
      result += 3 * gcd(comb[0], gcd(comb[1], comb[2]));
    }else{
      result += 6 * gcd(comb[0], gcd(comb[1], comb[2]));
    }
  }
  console.log(result)
}

solve(K)