import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

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

main = do
    [n, p] <- getIntList
    s <- getLine
    print $ foldl' (solve p) 0 (sequences s)

solve p k s | check s p = k + 1
            | otherwise = k
    where check s p = (read s') `mod` p == 0
              where s' = dropWhile (== '0') s

sequences s = [take j (drop i s) |i <- [0..(n-1)], j<-[1..(n-i)]]
    where n = length s