// package coffee.acupof.atcoder.solution.abc162.c

fun gcd(a: Int, b: Int): Int {
    return when {
        a == b -> a
        a > b -> gcd(b, a)
        else -> gcd(a,b - a)
    }
}

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

    val memo = (1..k).map { ab ->
        (1..k).map { c ->
            gcd(ab, c)
        }.sum()
    }.toIntArray()

    var sum = 0

    for (a in 1..k) {
        for (b in 1..k){
            sum += memo[gcd(a, b) - 1]
        }
    }
    println(sum)
}