import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val k = sc.nextInt()

  println(abc162c(k))
}

private fun abc162c(k: Int): Int {
  var ans = 0
  for (i in 1..k) {
    for (j in 1..k) {
      for (l in 1..k) {
        val list = mutableListOf(i, j, l)
        ans += ngcd162(list)
      }
    }
  }


  return ans
}

private fun ngcd162(a: List<Int>): Int {
    var res: Int
    res = a.get(0)
    for (i in 1 until a.size) {
        if (res == 1) break
        res = gcd162(a.get(i), res)
    }
    return res
}

private fun gcd162(a: Int, b: Int): Int {
    if (b > 0) {
        return gcd162(b, a % b)
    }
    return a
}