Count numbers up to N that cannot be expressed as sum of at least two consecutive positive integers | Java program for the above approach ; 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 integers ; 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
import java . util . * ; class GFG { static boolean isPowerof2 ( int n ) { return ( ( n & ( n - 1 ) ) > 0 && n > 0 ) ; } static void countNum ( int N ) { int count = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { boolean flag = isPowerof2 ( i ) ; if ( ! flag ) { count ++ ; } } System . out . print ( count + "NEW_LINE"); } public static void main ( String [ ] args ) { int N = 100 ; countNum ( N ) ; } }