-- file: fctrl.hs -- http://www.codechef.com/problems/FCTRL/ {-# LANGUAGE BangPatterns #-} {-# OPTIONS_GHC -O2 #-} module Main where import qualified Data.ByteString.Char8 as S import IO main :: IO () main = mapM_ (print . fctrl) . tail . readInts =<< S.getContents where readInts s = case S.readInt s of -- lazily reads current line Nothing -> [] Just (k,t) -> k : readInts (S.tail t) fctrl :: Int -> Int fctrl = fctrl' 0 where fctrl' :: Int -> Int -> Int fctrl' r n | n < 5 = r | otherwise = fctrl' (r + n') n' where n' = div n 5