Number of odd and even results for every value of x in range [ min , max ] after performing N steps | C ++ program to print Number of odd / even results for every value of x in range [ min , end ] after performing N steps ; Function that prints the number of odd and even results ; If constant at layer i is even , beven is true , otherwise false . If the coefficient of x at layer i is even , aeven is true , otherwise false . ; If any of the coefficients at any layer is found to be even , then the product of all the coefficients will always be even . ; Checking whether the constant added after all layers is even or odd . ; Assuming input x is even . ; Assuming input x is odd . ; Displaying the counts . ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void count_even_odd ( int min , int max , int steps [ ] [ 2 ] ) { int a , b , even , odd ; bool beven = true , aeven = false ; int n = 2 ; for ( int i = 0 ; i < n ; i ++ ) { a = steps [ i ] [ 0 ] , b = steps [ i ] [ 1 ] ; if ( ! ( aeven a & 1 ) ) aeven = true ; if ( beven ) { if ( b & 1 ) beven = false ; } else if ( ! ( a & 1 ) ) { if ( ! ( b & 1 ) ) beven = true ; } else { if ( b & 1 ) beven = true ; } } if ( beven ) { even = ( int ) max / 2 - ( int ) ( min - 1 ) / 2 ; odd = 0 ; } else { even = ( int ) max / 2 - ( int ) ( min - 1 ) / 2 ; odd = 0 ; } if ( ! ( beven ^ aeven ) ) even += max - min + 1 - ( int ) max / 2 + ( int ) ( min - 1 ) / 2 ; else odd += max - min + 1 - ( int ) max / 2 + ( int ) ( min - 1 ) / 2 ; cout << " even ▁ = ▁ " << even << " , ▁ odd ▁ = ▁ " << odd << endl ; } int main ( ) { int min = 1 , max = 4 ; int steps [ ] [ 2 ] = { { 1 , 2 } , { 3 , 4 } } ; count_even_odd ( min , max , steps ) ; return 0 ; }