import io.StdIn._

object Main extends App {
  val line1 = readLine.split(" ").map(_.toInt)
  val N = line1(0)
  val P = line1(1)

  val S = readLine.stripMargin

  val matrix = Array.fill[Array[Int]](N)(Array.fill[Int](N)(0))
  var divisibleCount = 0

  for (i <- 0 until N) {
    for (j <- (N - i - 1) until N) {

      val remaining = if (j == (N - i - 1)) {
        val singleDigit = S.substring(j, j + 1).toInt
        singleDigit % P
      } else {
        val remainingOnLeft = matrix(i)(j - 1)
        val remainingOnTop = matrix(N - j - 1)(j)
        (remainingOnLeft * 10 + remainingOnTop) % P
      }

      if (remaining == 0) {
        divisibleCount += 1
      }

      matrix(i)(j) = remaining
    }
  }

  println(divisibleCount)
}
