tailrec fun gcd(a: Int, b: Int = 0): Int = if(b == 0) { a } else { gcd(b, a % b) }
fun main(args: Array<String>) {
    val K = readLine()!!.toInt()

    var result = 0L
    for(a in 1..K) {
        for(b in 1..K) {
            for(c in 1..K) {
                result += gcd(gcd(a,b), c)
            }
        }
    }
    println(result)
}