import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B

readInt :: B.ByteString -> Maybe (Int,B.ByteString)
readInt xs = do
    (x,ys) <- B.readInt xs
    return (x,B.tail ys)

readPer :: B.ByteString -> Maybe (Int,B.ByteString)
readPer xs = let x = read $ [B.head xs] :: Int in return (x,B.tail xs)

conv :: VU.Vector Int -> Int
conv xs = if VU.null xs then 0 else 10*(conv $ VU.init xs) + VU.last xs

main :: IO ()
main = do
    (n,p) <- (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
    s <- VU.unfoldrN n readPer <$> B.getLine
    print $ length $ [ () | m <- [1..n], i <- [0..n-m], conv (VU.slice i m s) `mod` p == 0]