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

    var sum = 0L

    for (i in 1..n) {
        for (j in 1..n) {
            for (k in 1..n) {
                sum += gcd(i, j, k)
            }
        }
    }

    println(sum)
}

fun gcd(a : Int, b : Int, c : Int) : Int {
    val min = Math.min(Math.min(a, b), c)

    for (i in min downTo 1) {
        if (a % i == 0 && b % i == 0 && c % i == 0) return i
    }

    return 1
}
