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

fun gcd(a:Int, b:Int, c:Int):Int {
    return gcd2(gcd2(a,b), c)
}

fun main() {
    val K:Int = readLine()!!.toInt()
    var ans:Int = 0
    for (a in 1..K) {
        for (b in 1..K) {
            for (c in 1..K) {
                ans += gcd(a,b,c)
            }
        }
    }
    println(ans)
}