const main = (inputs) => {
  var num = inputs - 0;
  var sum = 0;

  for (var i = 1; i <= num; i++) {
    for (var j = 1; j <= num; j++) {
      for (var k = 1; k <= num; k++) {
        sum = sum + gcd(i, j, k);
      }
    }
  }

}
main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));


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
}