import java.io.PrintWriter

fun main() {
    val pw = PrintWriter(System.out)

    val k = readInputLine().toLong()

    var ans = 0L

    for (a in LongRange(1L, k)) {
        for (b in LongRange(1L, k)) {
            for (c in LongRange(1L, k)) {
                ans += gcd(gcd(a, b), c)
            }
        }
    }

    pw.println(ans)

    pw.flush()
}

fun readInputLine(): String {
    return readLine()!!
}

tailrec fun gcd(a: Long, b: Long): Long =
    when {
        b > a -> gcd(b, a)
        b == 0L -> a
        else -> gcd(b, a % b)
    }
