tailrec fun gcd(a:Int,b:Int):Int=if(b==0) a else gcd(b,a%b)

fun main() {
	val n=readLine()!!.toInt()
	println((1..n).asSequence()
			.flatMap {a-> (1..n).asSequence().map {b-> gcd(a,b)}}
			.flatMap {a-> (1..n).asSequence().map {b-> gcd(a,b)}}
			.sum())
}
