// Sum of gcd of Tuples (Easy)
func gcd(_ a:Int, _ b:Int) -> Int {
  if a == 1 || b == 1 {
    return 1
  }
  if a == b {
    return a
  }
  return gcd(min(a, b), abs(b-a))
}


func main() {
  let n = Int(readLine()!)!
  var sum = 0
  for a in 1...n {
    for b in 1...n {
      for c in 1...n {
        sum += gcd(gcd(a,b), c)
      }
    }
  }
  print(sum)
}

main()