fun main() {
    val numK = readLine()!!.toInt()
    val gcdList = mutableListOf<Int>()

    for(i in 1 .. numK ){
        for(j in 1 .. numK){
            for(k in 1 .. numK){
                gcdList.add(gcd(i, gcd(j, k)))
            }
        }
    }


    println(gcdList.sum())
}

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