fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    var ans = 0
    for (a in 1..n) {
        for (b in a..n) {
            for (c in b..n) {
                ans += if (a == b && b == c) {
                    gcd3(a,b,c)
                } else if (a==b || b ==c) {
                    gcd3(a,b,c)*3
                } else {
                    gcd3(a,b,c)*6
                }
            }
        }
    }
    println(ans)
}
fun gcd(a:Int,b:Int):Int {
    if (b == 0) {
        return a
    }
    return gcd(b,a%b)
}
fun gcd3(a: Int,b: Int,c:Int):Int {
    return gcd(gcd(a,b),c)
}