fun main(args: Array<String>){
    val input = readLine()!!.toInt()
    var total = 0L
    for (i in 1..input){
        for (j in 1..input){
            for (k in 1..input){
                total += gcd(gcd(i,j),k)
            }
        }
    }
    println(total)
}

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