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