Check if given coins can be used to pay a value of S | Function to check if it is possible to pay a value ; Loop to add the value of coin A ; Condition to check if it is possible to pay a value of S ; Driver Code
def knowPair ( a , b , n , s , m ) : NEW_LINE INDENT i = 0 NEW_LINE rem = 0 NEW_LINE count_b = 0 NEW_LINE flag = 0 NEW_LINE while ( i <= a ) : NEW_LINE INDENT rem = s - ( n * i ) NEW_LINE count_b = rem // m NEW_LINE if ( rem % m == 0 and count_b <= b ) : NEW_LINE INDENT flag = 1 NEW_LINE DEDENT i += 1 NEW_LINE DEDENT if ( flag == 1 ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT A = 1 NEW_LINE B = 2 NEW_LINE n = 3 NEW_LINE S = 4 NEW_LINE m = 2 NEW_LINE knowPair ( A , B , n , S , m ) NEW_LINE DEDENT