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

fun main() {
	val n=readLine()!!.toInt()
	var r=0L
	for(i in 1..n) {
		for(j in 1..n) {
			val t=gcd(i,j)
			for(k in 1..n) {
				r+=gcd(t,k)
			}
		}
	}
	println(r)
}
