fun main() {
    val l = Integer.parseInt(readLine())
    var ans = 0
    for (i in 1 until l+1) {
        for (j in 1 until l+1) {
            for (k in 1 until l+1) {
                ans += gcd(i, gcd(j, k))
            }
        }
    }
    println(ans)
}

fun gcd(a: Int, b: Int): Int {
    var aGcd = a
    var bGcd = b
    var gcdGcd: Int
    while (true) {
        gcdGcd = aGcd % bGcd
        aGcd = bGcd
        bGcd = gcdGcd
        if (gcdGcd == 0) break
    }
    return aGcd
}