const gcd = (m, n) => {
  while (n > 0) {
    const r = m % n
    m = n
    n = r
  }
  return m
}

const Main = (input) => {
  const tmp = parseInt(input.trim())

  let result = 0

  for (let i = 1; i <= tmp; ++i) {
    for (let j = 1; j <= tmp; ++j) {
      for (let k = 1; k <= tmp; ++k) {
        result += gcd(gcd(i, j), k)
      }
    }
  }

  console.log(result)
  return result
}

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