Find an integral solution of the non | Java program to implement the above approach ; 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
import java . util . * ; class GFG { static int power ( int x , int N ) { int res = 1 ; while ( N > 0 ) { if ( ( N & 1 ) != 0 ) { res = ( res * x ) ; } x = ( x * x ) ; N = N >> 1 ; } return res ; } static void findValX_Y ( int N ) { if ( N <= 1 ) { System . out . println ( - 1 ) ; return ; } int xMax ; xMax = ( int ) Math . log ( N ) ; int yMax ; yMax = ( int ) ( Math . log ( N ) / Math . log ( 5.0 ) ) ; for ( int i = 1 ; i <= xMax ; i ++ ) { for ( int j = 1 ; j <= yMax ; j ++ ) { int a = power ( 2 , i ) ; int b = power ( 5 , j ) ; if ( a + b == N ) { System . out . print ( i + " ▁ " + j ) ; return ; } } } System . out . println ( " - 1" ) ; } public static void main ( String args [ ] ) { int N = 129 ; findValX_Y ( N ) ; } }