IF MSD < 4. For example if n is 328 , then count of numbers is sum of following . 1 ) Count of numbers from 1 to 299 a 2 ) Count of numbers from 300 to 328 , recur for 28
return ( $ msd ) * $ a [ $ d ] + countNumbersWith4 ( $ n % $ p ) ; }