import           Control.Monad
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Maybe
import qualified Data.Vector.Unboxed.Mutable as VM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  [n, p] <- getIntList
  s <- BS.getLine

  v <- VM.new p
  VM.set v (0::Int)
  VM.write v 0 1 -- U0 `mod` p == 0                                                                                       
  let solve25 i a | i > n = print a
                  | otherwise = do
                      let c = BS.index s (n-i)
                          di = ord c - ord '0'
                          x = if di `mod` p == 0 then n - i + 1 else 0
                      solve25 (i+1) (a+x)

      solve i a | i > n = print a
                | otherwise = do
                    let ui = (fst . fromJust . BS.readInteger) $ BS.drop (n-i) s
                        m = fromIntegral (ui `mod` fromIntegral p) :: Int
                    y <- VM.read v m
                    VM.write v m (y+1)
                    solve (i+1) (a+y)

  if 10 `mod` p == 0
    then solve25 1 0
    else solve 1 0