Check if N contains all digits as K in base B | Java implementation of above approach ; 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 ; Driver code ; Given number N ; Given base B ; Given digit K ; Function call
import java . util . * ; class GFG { static int findNumberOfDigits ( int n , int base ) { int dig = ( ( int ) Math . floor ( Math . log ( n ) / Math . log ( base ) ) + 1 ) ; return dig ; } static boolean isAllKs ( int n , int b , int k ) { int len = findNumberOfDigits ( n , b ) ; int sum = k * ( 1 - ( int ) Math . pow ( b , len ) ) / ( 1 - b ) ; return sum == n ; } public static void main ( String [ ] args ) { int N = 13 ; int B = 3 ; int K = 1 ; if ( isAllKs ( N , B , K ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }