tailrec fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)

fun main(args: Array<String>) {
    val k = readLine()!!.toInt()
    (1..k).sumBy { a ->
        (1..k).sumBy { b ->
            (1..k).sumBy { c ->
                gcd(gcd(a,b),c)
            }
        }
    }.let { println(it) }
}
