For calculating the upper bound of the sequence .
v = [ ] ; while ( x > 0 ) { v . push ( x % 10 ) ; x = parseInt ( x / 10 ) ; } v . reverse ( ) ; N = v . length ; } function fun ( pos , sum , st , check , f ) { if ( pos == N ) {