func gcd(_ a: Int, _ b: Int, _ c: Int) -> Int {
  let ab = gcd(a, b)
  return gcd(ab, c)
}

func gcd(_ a: Int, _ b: Int) -> Int {
  if b == 0 { return a }
  return gcd(b, a % b)
}

let k = Int(readLine()!)!
var result = 0
for i in 1...k {
  for j in 1...k {
    for l in 1...k {
      result += gcd(i, j, l)
    }
  }
}
print(result)