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 ; Driver Code ; taking inputs ; function to check
def isRepunitNum ( n , b ) : NEW_LINE INDENT length = 0 ; NEW_LINE countOne = 0 ; NEW_LINE while ( n != 0 ) : NEW_LINE INDENT r = n % b ; NEW_LINE length += 1 ; NEW_LINE if ( r == 1 ) : NEW_LINE INDENT countOne += 1 ; NEW_LINE DEDENT n = n // b ; NEW_LINE DEDENT return countOne >= 3 and countOne == length ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 31 ; NEW_LINE base = 2 ; NEW_LINE if ( isRepunitNum ( n , base ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT DEDENT