object Main extends App{
  import scala.io.StdIn._
  @scala.annotation.tailrec
  def gcd(a: Long, b: Long): Long = {
    if(b == 0L) a
    else gcd(b, a%b)
  }
  val n=readLong()
  var ans:Long=0L
  for{i <- (1L to n);j<- (1L to n);k <-(1L to n)}{
    ans+=gcd(k,gcd(i,j))
  }
  println(ans)
}