import scala.io.StdIn._

object Main extends App {

  val line = readLine.split(" ")
  val N = line(0).toInt
  val P = line(1).toInt
  val S = readLine

  var count = 0
  for (i <- 0 until N) {
    for (j <- (i + 1) until (N + 1)) {
      val sub = S.substring(i, j)
      if (BigDecimal(sub) % P == 0) {
        count += 1
      }
    }
  }

  println(count)
}


