Count the number of currency notes needed | C ++ implementation of the approach ; Function to return the amount of notes with value A required ; If possible ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int bankNotes ( int A , int B , int S , int N ) { int numerator = S - ( B * N ) ; int denominator = A - B ; if ( numerator % denominator == 0 ) return ( numerator / denominator ) ; return -1 ; } int main ( ) { int A = 1 , B = 2 , S = 7 , N = 5 ; cout << bankNotes ( A , B , S , N ) << endl ; }