Find an integral solution of the non | Function to find the value of power ( X , N ) ; Stores the value of ( X ^ N ) ; Calculate the value of power ( x , N ) ; If N is odd ; Update res ; Update x ; Update N ; Function to find the value of X and Y that satisfy the condition ; Base Case ; Stores maximum possible of X . ; Update xMax ; Stores maximum possible of Y . ; Update yMax ; Iterate over all possible values of X ; Iterate over all possible values of Y ; Stores value of 2 ^ i ; Stores value of 5 ^ j ; If the pair ( i , j ) satisfy the equation ; If no solution exists ; Driver Code
function power ( x , N ) { let res = 1 ; while ( N > 0 ) { if ( ( N & 1 ) != 0 ) { res = ( res * x ) ; } x = ( x * x ) ; N = N >> 1 ; } return res ; } function findValX_Y ( N ) { if ( N <= 1 ) { document . write ( - 1 ) ; return ; } let xMax ; xMax = Math . log ( N ) ; let yMax ; yMax = Math . log ( N ) / Math . log ( 5.0 ) ; for ( let i = 1 ; i <= xMax ; i ++ ) { for ( let j = 1 ; j <= yMax ; j ++ ) { let a = power ( 2 , i ) ; let b = power ( 5 , j ) ; if ( a + b == N ) { document . write ( i + " " + j ) ; return ; } } } document . write ( " " ) ; } let N = 129 ; findValX_Y ( N ) ;