fun main() {
    val memo = mutableMapOf<Set<Int>, Int>()

    //最大公約数・
    fun gcd(a: Int, b: Int): Int {
        return if (b > 0) gcd(b, a % b) else a
    }

    val K = readLine()!!.toInt()


    var sum = 0
    for (i in 1..K) {
        for (l in 1..K) {
            for (j in 1..K) {
                sum += gcd(gcd(i, l), j)
            }
        }
    }
    println(sum)
}