import scala.io.StdIn.readLine

object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val tmp = readLine()
    val n = tmp.split(" ")(0).toInt
    val p = tmp.split(" ")(1).toLong
    val s = readLine

    var ans = 0
    for (i <- 0 until n; j <- i + 1 until n + 1) {
      val t = BigDecimal(s.substring(i, j))
      if (t % p == 0) ans += 1
    }

    println(ans)
  }

}
