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 $ solve p s

solve p s = length [() | i <- [0..(n-1)], j<-[1..(n-i)], check p (take j (drop i s))]
    where n = length s
          check p s = (read s :: Int) `mod` p == 0