local n, p = io.read("*n", "*n", "*l")
local str = io.read()
local t = {}
for i = 1, p do
  t[i] = 0
end
t[1] = 1
local mul = 1
local cur = 0
local ret = 0
for i = n, 1, - 1 do
  local num = tonumber(str:sub(i, i))
  cur = (cur + mul * num) % p
  ret = ret + t[cur + 1]
  t[cur + 1] = t[cur + 1] + 1
  mul = (mul * 10) % p
end
print(ret)
