Check if N contains all digits as K in base B | Function to print the number of digits ; Calculate log using base change property and then take its floor and then add 1 ; Return the output ; Function that returns true if n contains all one 's in base b ; Calculate the sum ; Given number N ; Given base B ; Given digit K ; Function call
function findNumberOfDigits ( n , base ) { var dig = ( Math . floor ( Math . log ( n ) / Math . log ( base ) ) + 1 ) ; return ( dig ) ; } function isAllKs ( n , b , k ) { var len = findNumberOfDigits ( n , b ) ; var sum = k * ( 1 - Math . pow ( b , len ) ) / ( 1 - b ) ; if ( sum == n ) { return ( sum ) ; } } var N = 13 ; var B = 3 ; var K = 1 ; if ( isAllKs ( N , B , K ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }