Number of odd and even results for every value of x in range [ min , max ] 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
< ? php function count_even_odd ( $ min , $ max , $ steps ) { $ beven = true ; $ aeven = false ; $ n = 2 ; for ( $ 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 ; echo " even = " ▁ , ▁ $ even , STRNEWLINE TABSYMBOL TABSYMBOL " , odd = " , ▁ $ odd , ▁ " " } $ min = 1 ; $ max = 4 ; $ steps = array ( array ( 1 , 2 ) , array ( 3 , 4 ) ) ; count_even_odd ( $ min , $ max , $ steps ) ; ? >