import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val k = sc.nextInt()

    val one = (1 to k).map { x => gcd(x, x, x) }
    val two = (1 to k).combinations(2).map(v => gcd(v(0), v(1), v(1)) + gcd(v(0), v(1), v(1)))
    val three = (1 to k).combinations(3).map(v => gcd(v(0), v(1), v(2)))
    println(one.sum + 3 * two.sum + 6 * three.sum)

    //
    //    val sum = (1 to k).flatMap { a =>
    //      (1 to k).flatMap { b =>
    //        (1 to k).map { c =>
    //          gcd(a, b, c)
    //        }
    //      }
    //    }.sum
    //    println(sum)
  }

  def gcd(a: Int, b: Int, c: Int): Int = gcd(gcd(a, b), c)

  def gcd(x: Int, y: Int): Int = y match {
    case 0 => x
    case _ => gcd(y, x % y)
  }

}
