Expressing a number as sum of consecutive | Set 2 ( Using odd factors ) | returns the number of odd factors ; If i is an odd factor and n is a perfect square ; If n is not perfect square ; N as sum of consecutive numbers
< ? php function countOddFactors ( $ n ) { $ odd_factors = 0 ; for ( $ i = 1 ; 1 * $ i * $ i <= $ n ; $ i ++ ) { if ( $ n % $ i == 0 ) { if ( 1 * $ i * $ i == $ n ) { if ( $ i & 1 ) $ odd_factors ++ ; } else { if ( $ i & 1 ) $ odd_factors ++ ; $ factor = $ n / $ i ; if ( $ factor & 1 ) $ odd_factors ++ ; } } } return $ odd_factors - 1 ; } $ N = 15 ; echo ( countOddFactors ( $ N ) . ( " " ) ) ; $ N = 10 ; echo ( countOddFactors ( $ N ) ) ; ? >