Count integers up to N which can be represented as sum of two or more consecutive numbers | Function to check if the number N can be expressed as sum of 2 or more consecutive numbers or not ; Function to count integers in the range [ 1 , N ] that can be expressed as sum of 2 or more consecutive numbers ; Stores the required count ; Driver Code
function isPossible ( N ) { return ( ( ( N & ( N - 1 ) ) & N ) ) ; } function countElements ( N ) { var count = 0 ; for ( i = 1 ; i <= N ; i ++ ) { if ( isPossible ( i ) != 0 ) count ++ ; } document . write ( count ) ; } var N = 15 ; countElements ( N ) ;