fun main(arg: Array<String>) {
    val K = nextInt()
    var ans = 0L
    repeat(K, K, K) { a, b, c ->
        ans += gcd(a.plus1(), gcd(b.plus1(), c.plus1()))
    }
    return println(ans)
}
fun Int.plus1() = (this + 1).toLong()
tailrec fun gcd(a: Long, b: Long): Long = if (a % b == 0L) b else gcd(b, a % b)
fun lcm(a: Long, b: Long): Long = a / gcd(a, b) * b
inline fun repeat(times1: Int, times2: Int, times3: Int, action: (Int, Int, Int) -> Unit) {
    for (index1 in 0 until times1)
        for (index2 in 0 until times2)
            for (index3 in 0 until times3) {
                action(index1, index2, index3)
            }
}

fun next() = readLine()!!
fun nextInt(offset: Int = 0) = Integer.parseInt(next()) + offset
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
