Description
Suppose a pile of n coins consisting of 1 point, 2 points, and 5 points has a total face value of m points, and find out how many possible combinations there are (the number of coins of a certain face value can be 0).
Input
The first line of the input data has a positive integer T, indicating that there are T sets of test data; the
next T line, each line has two numbers n, m, n and m have the same meaning as above.
Output
For each set of test data, please output the number of possible combinations;
each set of output occupies one line.
Sample Input
2 3 5 4 8
Sample Output
1 2
#include <iostream>
using namespace std;
int main()
{
int n, m;
int t;
int top, bottom;
cin >> t;
while (t--){
cin >> n >> m;
if (m>5*n || m<n)
cout << "0" << endl;
else{
top = n * 5;
bottom = 0;
if ((m-n)/4<top)
top = (m-n) / 4;
if ((m-n*2) >= 3)
bottom = (m-n*2+2) / 3;
cout << top-bottom+1 << endl;
}
}
return 0;
}