process.stdin.setEncoding('utf-8');
process.stdin.on('data', function (data) {
  let sum = 0
  for (let i = 1; i < Number(data) + 1; i++) {
    for (let j = 1; j < Number(data) + 1; j++) {
      for (let k = 1; k < Number(data) + 1; k++) {
        const jk = gcd(j,k)
        const ijk = gcd(jk,i)
        sum = sum + ijk
      }
    }
  }
  console.log(sum)
});


function gcd(m, n) {
  let r;

  if(m < n) {  
    r = m;  
    m = n;
    n = r;
  }

  while ((r = m % n) != 0) {
    m = n;
    n = r;
  }

  return n;
}