import io.StdIn._

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

  val S = readLine.toCharArray.map(_.toInt - 48)

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

  for (i <- 0 until N) {
    val remaining = S(i) % P
    if (remaining == 0) {
      divisibleCount += 1
    }
    topRemainingList(i) = remaining
  }

  var lastRemaining = 0
  for (i <- 0 until N) {
    for (j <- (N - i) until N) {

      val remainingOnLeft =
        if (j == N - i) topRemainingList(j - 1) else lastRemaining
      val remainingOnTop = topRemainingList(j)
      val remaining = (remainingOnLeft * 10 + remainingOnTop) % P

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

      lastRemaining = remaining
    }
  }

  println(divisibleCount)
}
