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
< ? php function hasConsecutiveZeroes ( $ N , $ K ) { $ z = toK ( $ N , $ K ) ; if ( check ( $ z ) ) print ( " Yes " ) ; else print ( " No " ) ; } function toK ( $ N , $ K ) { $ w = 1 ; $ s = 0 ; while ( $ N != 0 ) { $ r = $ N % $ K ; $ N = ( int ) ( $ N / $ K ) ; $ s = $ r * $ w + $ s ; $ w *= 10 ; } return $ s ; } function check ( $ N ) { $ fl = false ; while ( $ N != 0 ) { $ r = $ N % 10 ; $ N = ( int ) ( $ N / 10 ) ; if ( $ fl == true and $ r == 0 ) return false ; if ( $ r > 0 ) { $ fl = false ; continue ; } $ fl = true ; } return true ; } $ N = 15 ; $ K = 8 ; hasConsecutiveZeroes ( $ N , $ K ) ; ? >