Check if a given number is one less than twice its reverse | Python3 program to implement the above approach ; Function to check y is a power of x ; logarithm function to calculate value ; Compare to the result1 or result2 both are equal ; Function to check if N satisfies the equation 2 * reverse ( n ) = n + 1 ; Driver Code
import math NEW_LINE def isPower ( x , y ) : NEW_LINE INDENT res1 = math . log ( y ) // math . log ( x ) NEW_LINE res2 = math . log ( y ) // math . log ( x ) NEW_LINE return ( res1 == res2 ) NEW_LINE DEDENT def check ( n ) : NEW_LINE INDENT x = ( n + 7 ) // 8 NEW_LINE if ( ( n + 7 ) % 8 == 0 and isPower ( 10 , x ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT n = 73 NEW_LINE if ( check ( n ) != 0 ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT