object Main extends App {
  val nk = io.StdIn.readLine().split(" ").map(_.toInt)
  val N = nk(0)
  val K = nk(1)
  val isEven = K % 2 == 0
  val zsize = (1 to N).toList.count(_ % K == 0)
  if (isEven) {
    val half = (1 to N).toList.count(_ % K == K / 2)
    val res = zsize + 3 * zsize * (zsize - 1) + zsize * (zsize - 1) * (zsize - 2) + half + 3 * half * (half - 1) + half * (half - 1) * (half - 2)
    println(res)
  }
  else {
    val res = zsize + 3 * zsize * (zsize - 1) + zsize * (zsize - 1) * (zsize - 2)
    println(res)
  }
}
