Cunningham Numbers | Function to check if a number can be expressed as a ^ b . ; Function to check if N is a Cunningham number ; Given Number ; Function Call
function isPower ( a ) { if ( a == 1 ) return true ; for ( let i = 2 ; i * i <= a ; i ++ ) { let val = Math . log ( a ) / Math . log ( i ) ; if ( ( val - parseInt ( val ) < 0.00000001 ) ) return true ; } return false ; } function isCunningham ( n ) { return isPower ( n - 1 ) || isPower ( n + 1 ) ; } let n = 126 ; if ( isCunningham ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;