Loop to iterate from 1 to N and calculating number of natural numbers for every ' i ' th digit .
for ( int i = 1 ; i <= N ; i ++ ) { sum += ( int ) ( ( B - 1 ) * Math . Pow ( B , i - 1 ) ) ; } return sum ; }