Vector P to store the base k representation of the number
let p = new Array ( String ( n ) . length + 2 ) . fill ( 0 ) ; let index = 0 ; let x = n ; while ( x > 0 ) { p [ index ] = ( x % k ) ; x = Math . floor ( x / k ) ; index ++ ; } let idx = 0 ; for ( let i = 0 ; i < p . length - 1 ; ++ i ) { if ( p [ i ] >= 2 ) {