Count numbers up to N that cannot be expressed as sum of at least two consecutive positive integers | Function to check if a number can be expressed as a power of 2 ; f N is power of two ; Function to count numbers that cannot be expressed as sum of two or more consecutive + ve integers ; Stores the resultant count of letegers ; Iterate over the range [ 1 , N ] ; Check if i is power of 2 ; Increment the count if i is not power of 2 ; Print the value of count ; Driver code
function isPowerof2 ( n ) { return ( ( n & ( n - 1 ) ) && n ) ; } function countNum ( N ) { let count = 0 ; for ( let i = 1 ; i <= N ; i ++ ) { let flag = isPowerof2 ( i ) ; if ( ! flag ) { count ++ ; } } document . write ( count + " " ) ; } let N = 100 ; countNum ( N ) ;