Check if a given number is one less than twice its reverse | Java 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 java . io . * ; import java . util . * ; class GFG { static boolean isPower ( int x , int y ) { double res1 = Math . log ( y ) / Math . log ( x ) ; double res2 = Math . log ( y ) / Math . log ( x ) ; return ( res1 == res2 ) ; } static boolean check ( int n ) { int x = ( n + 7 ) / 8 ; if ( ( n + 7 ) % 8 == 0 && isPower ( 10 , x ) ) return true ; else return false ; } public static void main ( String [ ] args ) { int n = 73 ; if ( check ( n ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }