Check if X can be reduced to 0 in exactly T moves by substracting D or 1 from it | Java program for the above approach ; Function to check the above problem condition ; Check for base cases ; Check if D - 1 is a divisor of X - T ; Driver Code
import java . util . * ; class GFG { static int possibleReachingSequence ( int X , int D , int T ) { if ( X < T ) { System . out . println ( " NO " ) ; return 0 ; } if ( T * D < X ) { System . out . println ( " NO " ) ; return 0 ; } if ( ( X - T ) % ( D - 1 ) == 0 ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } return 0 ; } public static void main ( String args [ ] ) { int X = 10 , D = 3 , T = 6 ; possibleReachingSequence ( X , D , T ) ; } }