function Main (K) {
  K = parseInt(K, 10);
  var ans = 0;
  for (var a = 1; a <= K; a++) {
    for (var b = 1; b <= K; b++) {
      for (var c = 1; c <= K; c++) {
        ans += gcd(a, b, c);
      }
    }
  }
  console.log(ans);
  function gcd() {
    var f = (a, b) => b ? f(b, a % b) : a
    var ans = arguments[0]
    for (var i = 1; i < arguments.length; i++) {
        ans = f(ans, arguments[i]); 
    }
    return ans 
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));