Check whether a number has consecutive 0 's in the given base or not | We first convert to given base , then check if the converted number has two consecutive 0 s or not ; Function to convert N into base K ; Weight of each digit ; Function to check for consecutive 0 ; Flag to check if there are consecutive zero or not ; If there are two consecutive zero then returning False ; Driver code
def hasConsecutiveZeroes ( N , K ) : NEW_LINE INDENT z = toK ( N , K ) NEW_LINE if ( check ( z ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT def toK ( N , K ) : NEW_LINE INDENT w = 1 NEW_LINE s = 0 NEW_LINE while ( N != 0 ) : NEW_LINE INDENT r = N % K NEW_LINE N = N // K NEW_LINE s = r * w + s NEW_LINE w * = 10 NEW_LINE DEDENT return s NEW_LINE DEDENT def check ( N ) : NEW_LINE INDENT fl = False NEW_LINE while ( N != 0 ) : NEW_LINE INDENT r = N % 10 NEW_LINE N = N // 10 NEW_LINE if ( fl == True and r == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( r > 0 ) : NEW_LINE INDENT fl = False NEW_LINE continue NEW_LINE DEDENT fl = True NEW_LINE DEDENT return True NEW_LINE DEDENT N , K = 15 , 8 NEW_LINE hasConsecutiveZeroes ( N , K ) NEW_LINE