import java.util.*

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

    var answer = 0L

    for (h in 1..k) {
        if (h == 1) {
            answer += k*k
        } else {
            for (i in 1..k) {
                val gcdhi = gcd(listOf(h,i))
                if (i == 1) {
                    answer += k
                } else {
                    for (j in 1..k) {
                        if (j == 1) {
                            answer += 1
                        } else if (h == i && h == j && i == j) {
                            answer += h
                        } else {
                            answer += gcd(listOf(gcdhi, j))
                        }
                    }
                }
            }
        }
    }
    println(answer)
}

fun gcd(list: List<Int>): Int {
    val stack = Stack<Int>()
    for (e in list) {
        stack.push(e)
    }
    while (1 < stack.size) {
        val pops = (0 until 2).map {
            stack.pop()
        }

        val minIndex = if (pops[1] < pops[0]) 1
        else 0

        stack.push(pops[minIndex])
        val r = pops[(minIndex + 1) % 2] % pops[minIndex]
        if (0 < r) {
            stack.push(r)
        }
    }
    return stack.pop()
}
