Repunit numbers | Java implementation to check if a number is Repunit Number ; 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
class GFG { static boolean isRepunitNum ( int n , int b ) { int length = 0 ; int countOne = 0 ; while ( n != 0 ) { int r = n % b ; length ++ ; if ( r == 1 ) countOne ++ ; n = n / b ; } return countOne >= 3 && countOne == length ; } public static void main ( String [ ] args ) { int n = 31 ; int base = 2 ; if ( isRepunitNum ( n , base ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }