Count integers up to N which can be represented as sum of two or more consecutive numbers | Java implementation of the above approach ; Function to count integers in the range [ 1 , N ] that can be expressed as sum of 2 or more consecutive numbers ; Count powers of 2 up to N ; Increment count ; Update current power of 2 ; Driver Code
import java . util . * ; class GFG { static void countElements ( int N ) { int Cur_Ele = 1 ; int Count = 0 ; while ( Cur_Ele <= N ) { Count ++ ; Cur_Ele = Cur_Ele * 2 ; } System . out . print ( N - Count ) ; } public static void main ( String [ ] args ) { int N = 15 ; countElements ( N ) ; } }