object Main extends App {
  @scala.annotation.tailrec
  def gcd(p: Int, q: Int): Int = if (p % q == 0) q else gcd(q, p % q)
  val sc = new java.util.Scanner(System.in)
  val range = 1 to sc.nextInt()
  println((for (i <- range; j <- range; k <- range) yield gcd(gcd(i, j), k)).sum)
}
