fun main(args: Array<String>) {

    val input = readLine()
    var n:Int = Integer.parseInt(input)
    var sum:Long = 0

    for(i in 1 until n+1){
        for(j in 1 until n+1){
            for(k in 1 until n+1){
                sum += gcd(i,j,k)
            }
        }
    }
    println(sum)
}

fun gcd(a:Int,b:Int,c:Int):Int{
    val v1 = calc_gcd(a,b)
    val v3 = calc_gcd(v1,c)
    return v3
}

fun calc_gcd(a:Int,b:Int):Int{
    if(a < b) return calc_gcd(b,a)
    if(b == 0) return a
    return calc_gcd(b, a % b)
}