fun main() {
    val k = readLine()!!.toInt()
    fun gcd(a: Int, b: Int): Int {
        return if (b == 0) a else gcd(b, a % b)
    }
    var ans = 0L
    for (a in 1..k) {
        for (b in 1..k) {
            for (c in 1..k) {
                ans += gcd(gcd(a, b), c)
            }
        }
    }
    println(ans)
}
