Repunit numbers | Function to check if a number contains all the digits 0 , 1 , . . , ( b - 1 ) an equal number of times ; to store number of digits of n in base B ; to count frequency of digit 1 ; condition to check three or more 1 's  and number of ones is equal to number  of digits of n in base B ; taking inputs ; function to check
function isRepunitNum ( n , b ) { let length = 0 ; let countOne = 0 ; while ( n != 0 ) { let r = n % b ; length ++ ; if ( r == 1 ) countOne ++ ; n = parseInt ( n / b ) ; } return countOne >= 3 && countOne == length ; } let n = 31 ; let base = 2 ; if ( isRepunitNum ( n , base ) ) document . write ( " " ) ; else document . write ( " " ) ;