• + 0 comments

    Haskell

    module Main where
    
    solve p d m s =
        let seqH = takeWhile (>= m) $ iterate (subtract d) p
            seqT = repeat m
            sums = scanl1 (+) $ seqH ++ seqT
         in length $ takeWhile (<= s) sums
    
    main :: IO ()
    main = do
        [p, d, m, s] <- fmap (map read . words) getLine
        print $ solve p d m s