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

  return gcd(b, a % b);
}

function main(input) {
  const K = parseInt(input);

  let res = 0;

  for (let c = 1; c <= K; ++c) {
    for (let b = 1; b <= K; ++b) {
      for (let a = 1; a <= K; ++a) {
        res += gcd(gcd(a, b), c);
      }
    }
  }
  console.log(res);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
