Maximum prime moves to convert X to Y | Java implementation of the approach ; Function to return the maximum operations required to convert X to Y ; X cannot be converted to Y ; If the difference is 1 ; If the difference is even ; Add 3 to X and the new difference will be even ; Driver code
class GFG { static int maxOperations ( int X , int Y ) { if ( X > Y ) return - 1 ; int diff = Y - X ; if ( diff == 1 ) return - 1 ; if ( diff % 2 == 0 ) return ( diff / 2 ) ; return ( 1 + ( ( diff - 3 ) / 2 ) ) ; } public static void main ( String [ ] args ) { int X = 5 , Y = 16 ; System . out . println ( maxOperations ( X , Y ) ) ; } }