object Main extends App {
  import scala.io.StdIn.readLine
  val input = readLine().split(" ").map(_.toInt)

  val n = input(0)
  val k = input(1)

  var count1 = 0
  var count2 = 0
  var count3 = 0
  // 3つとも同じ
  for (a <- 1 to n) {
    if ((a + a) % k == 0) {
      count1 += 1
      for (b <- 1 to n) {
        if (a != b && (a + b) % k == 0) {
          count2 += 1
          if (a < b) {
            for (c <- b + 1 to n) {
              if (a < b && b < c && b != c && c != a && (b + c) % k == 0 && (c + a) % k == 0) count3 += 1
            }
          }

        }
      }
    }
  }

  print(count1 + count2 * 3 + count3 * 6)
}