import java.util.Scanner


import scala.io.StdIn._

object Main extends App {

  val k = readInt()

  def solve() = {
    var ans = 0L
    for {
      a <- 1 to k
      b <- 1 to k
      c <- 1 to k
    } {
      ans += gcd(a,b,c)
    }
    ans
  }

  def gcd(x: Int, y: Int, z: Int): Int = {
    calcGCD(x, calcGCD(y, z))
  }

  def calcGCD(x: Int, y: Int): Int = {
    if(y == 0) x
    else calcGCD(y, x % y)
  }

  println(solve())

}

