Maximize the product of four factors of a Number | For calculation of a ^ b ; Function to check ; every odd and number less than 3. ; every number divisible by 4. ; every number divisible by 6. ; every number divisible by 10. ; for every even number which is not divisible by above values . ; Driver code
< ? php function modExp ( $ a , $ b ) { $ result = 1 ; while ( $ b > 0 ) { if ( $ b & 1 ) $ result = $ result * $ a ; $ a = $ a * $ a ; $ b /= 2 ; } return $ result ; } function check ( $ num ) { if ( $ num & 1 $ num < 3 ) return -1 ; else if ( $ num % 4 == 0 ) return modExp ( $ num / 4 , 4 ) ; else if ( $ num % 6 == 0 ) return modExp ( $ num / 3 , 2 ) * modExp ( $ num / 6 , 2 ) ; else if ( $ num % 10 == 0 ) return modExp ( $ num / 5 , 2 ) * ( $ num / 10 ) * ( $ num / 2 ) ; else return -1 ; } $ num = 10 ; echo check ( $ num ) ; ? >