let l = readLine()!.split(separator:" ").map{Int($0)!}
let n = l[0], p = l[1]
let s = readLine()!
var c = 0

for i in 0..<s.count {
  for j in 1...s.count-i {
    let str = s.dropFirst(i).prefix(j)
    if Int(str)! % p == 0 {
      c += 1
    }
  }
}

print(c)