Find Maximum length of number
for ( int i = 0 ; i < 9 ; i ++ ) { frac [ i ] = sum / arr [ i ] ; if ( frac [ i ] > maxi ) { pos = i ; maxi = frac [ i ] ; } } ans . insert ( 0 , string ( maxi , ( pos + 1 ) + '0' ) ) ; sum -= maxi * arr [ pos ] ;