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
function modExp ( a , b ) { let result = 1 ; while ( b > 0 ) { if ( b == 1 ) result = result * a ; a = a * a ; b = Math . floor ( b / 2 ) ; } return result ; } function check ( num ) { if ( num == 1 num < 3 ) return - 1 ; else if ( num % 4 == 0 ) return modExp ( Math . floor ( num / 4 ) , 4 ) ; else if ( num % 6 == 0 ) return modExp ( Math . floor ( num / 3 ) , 2 ) * modExp ( Math . floor ( num / 6 ) , 2 ) ; else if ( num % 10 == 0 ) return modExp ( Math . floor ( num / 5 ) , 2 ) * Math . floor ( num / 10 ) * Math . floor ( num / 2 ) ; else return - 1 ; } let num = 10 ; document . write ( check ( num ) ) ;