fun main(args: Array<String>){
    val k = readLine()
    val num = k!!.toInt()


    var sumGcd = 0
    for(a in 1..num){
        for(b in 1..num){
            for(c in 1..num){
                sumGcd += gcd(gcd(a, b), c)
            }
        }
    }
    println(sumGcd)
}

fun gcd(p: Int, q: Int) : Int{
    if(p % q == 0){
        return q
    }
    return gcd(q, p % q)
}