object Main extends App {
	val N = scala.io.StdIn.readLong

	var ans = 0L
	for(i<-1L to N; j<-1L to N; k<-1L to N){
		val tp = gcd(i, j)
		ans += gcd(k, tp)
	}

	println(ans)

	def gcd(a: Long, b: Long): Long = {
		if(b == 0L) return a
	  	else return gcd(b, a%b)
	}
}