Check if N can be represented as sum of distinct powers of 3 | Function to check whether the given N can be represented as the sum of the distinct powers of 3 ; Iterate until N is non - zero ; Termination Condition ; Right shift ternary bits by 1 for the next digit ; If N can be expressed as the sum of perfect powers of 3 ; Driver Code
function DistinctPowersOf3 ( N ) { while ( N > 0 ) { if ( N % 3 == 2 ) { document . write ( " " ) ; return ; } N = Math . floor ( N / 3 ) ; } document . write ( " " ) ; } let N = 91 ; DistinctPowersOf3 ( N ) ;