Generate first K multiples of N using Bitwise operators | Function to prvar the first K multiples of N ; Prvar the value of N * i ; Iterate each bit of N and add Math . pow ( 2 , pos ) , where pos is the index of each set bit ; Check if current bit at pos j is fixed or not ; For next set bit ; Driver Code
function Kmultiples ( n , k ) { var a = n ; for ( i = 1 ; i <= k ; i ++ ) { document . write ( n + " " + i + " " + a + " " ) ; var j = 0 ; while ( n >= ( 1 << j ) ) { a += n & ( 1 << j ) ; j ++ ; } } } var N = 16 , K = 7 ; Kmultiples ( N , K ) ;