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

fun main() {
    val n = readLine()?.toInt() ?: return
    var total = 0
    repeat(n) {
        val a = it + 1
        repeat(n) {
            val b = it + 1
            repeat(n) {
                val c = it + 1
                total += gcd(gcd(a, b), c)
            }
        }
    }
    println(total)
}
