import java.util.Scanner

object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val a = sc.nextInt //最初の整数が読み込まれる
    
    //val a = 200
    
    def gcd(x: Long, y: Long): Long = {
        if(y == 0) x
        else gcd(y, (x % y))
    }
    
    def tri_gcd(a: Long,b: Long, c:Long): Long ={
        var a2 = gcd(a,b)
        var b2 = c
        gcd(a2,b2)
    }
    
    var lst: Long = 0

    (1 to a).foreach{
        i =>
        (1 to a).foreach{
          j =>          
            (1 to a).foreach{
                k =>
                lst = lst + tri_gcd(i,j,k)
            }
        }
    }

println(lst)

  }
}
