fun main(args: Array<String>) = abc158e()

fun abc158e() {
    val (n, p) = readLine()!!.split(' ').map { it.toInt() }
    val s = readLine()!!.toCharArray().map { it.toString().toInt() }.toIntArray()

    var answer = 0L

    when (10 % p) {
        0 -> {
            for ((index, i) in s.withIndex()) {
                if (i % p == 0) answer += 1 + index
            }
        }
        else -> {
            val mods = IntArray(n + 1)
            var ten = 1
            for ((index, i) in s.reversed().withIndex()) {
                mods[index + 1] = (mods[index] + (i * ten % p)) % p
                ten *= 10
                ten %= p
            }

            val left = IntArray(p)
            for (m in mods) answer += left[m]++
        }
    }

    println(answer)
}
