Find an integral solution of the non | Python3 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
from math import log2 NEW_LINE def power ( x , N ) : NEW_LINE INDENT res = 1 NEW_LINE while ( N > 0 ) : NEW_LINE INDENT if ( N & 1 ) : NEW_LINE INDENT res = ( res * x ) NEW_LINE DEDENT x = ( x * x ) NEW_LINE N = N >> 1 NEW_LINE DEDENT return res NEW_LINE DEDENT def findValX_Y ( N ) : NEW_LINE INDENT if ( N <= 1 ) : NEW_LINE print ( - 1 ) NEW_LINE return NEW_LINE xMax = 0 NEW_LINE xMax = int ( log2 ( N ) ) NEW_LINE yMax = 0 NEW_LINE yMax = int ( log2 ( N ) / log2 ( 5.0 ) ) NEW_LINE for i in range ( 1 , xMax + 1 ) : NEW_LINE INDENT for j in range ( 1 , yMax + 1 ) : NEW_LINE INDENT a = power ( 2 , i ) NEW_LINE b = power ( 5 , j ) NEW_LINE if ( a + b == N ) : NEW_LINE INDENT print ( i , j ) NEW_LINE return NEW_LINE DEDENT DEDENT DEDENT print ( - 1 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 129 NEW_LINE findValX_Y ( N ) NEW_LINE DEDENT