fun main(){
    val K = readLine()!!.toInt()

    var ans: Long = 0
    for(a in 1..K){
        for(b in 1..K){
            var tmp = gcd(a, b)
            for(c in 1..K){
                ans += gcd(tmp, c)
            }
        }
    }

    println(ans)
}

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