Check if X can be reduced to 0 in exactly T moves by substracting D or 1 from it | C ++ Program to implement 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int possibleReachingSequence ( int X , int D , int T ) { if ( X < T ) { cout << " NO " ; return 0 ; } if ( T * D < X ) { cout << " NO " ; return 0 ; } if ( ( X - T ) % ( D - 1 ) == 0 ) { cout << " YES " ; } else { cout << " NO " ; } return 0 ; } int main ( ) { int X = 10 , D = 3 , T = 6 ; possibleReachingSequence ( X , D , T ) ; }