import Data.List
import qualified Data.Sequence as Seq
import Data.Foldable

mapOverTail :: ([a] -> b) -> [a] -> [b]
mapOverTail _ [] = []
mapOverTail f xs = (f xs):mapOverTail f (tail xs)

accumulate :: (Int, Int, Int) -> Int -> (Int, Int, Int)
accumulate (prevN, prime, sum) n = (modRes, prime, (if modRes == 0 then 1 else 0) + sum)
  where modRes = (prevN * 10 + n) `mod` prime

third :: (a, a, a) -> a
third (_, _, x) = x

main :: IO ()
main = do
  line <- getLine
  let (_:p:_) = (map (read :: String -> Int) . words) line
  str <- getLine
  let numStr = map (\x -> read [x] :: Int) str
  let noOfDivisibles = sum $ map third $ mapOverTail (foldl accumulate (0, p, 0)) numStr
  putStrLn $ show noOfDivisibles
