import kotlin.math.*
import java.util.*

fun gcd(a: Int, b: Int): Int {
  var x = a
  var y = b
  if (y < x) {
    x = b
    y = a
  }
  for (i in x downTo 1) {
    if (x % i == 0 && y % i == 0) return i
  }
  throw RuntimeException()
}

fun main(args: Array<String>) {
  val k = readLine()!!.toInt()
  var ans = 0
  for (x in 1..k) {
    for (y in 1..k) {
      val s = gcd(x, y)
      for (z in 1..k) {
        ans += gcd(s, z)
      }
    }
  }
  println(ans)
}
