fun main(args: Array<String>) {
    readLine()?.let {
        val loop = it.toLong()
        var sum = 0L

        for (a in 1..loop) {
            for (b in 1..loop) {
                for (c in 1..loop) {
                    sum += gcd(a, gcd(b, c))
                }
            }
        }
        println(sum)
    }
}

/** 最大公約数 ユークリッド互除法 */
fun gcd(a: Long, b: Long): Long {
    return if (a % b == 0L) {
        b
    } else {
        gcd(b, a % b)
    }
}