Description
假设一堆由1分、2分、5分组成的n个硬币总面值为m分,求一共有多少种可能的组合方式(某种面值的硬币可以数量可以为0)。
Input
输入数据第一行有一个正整数T,表示有T组测试数据;
接下来的T行,每行有两个数n,m,n和m的含义同上。
Output
对于每组测试数据,请输出可能的组合方式数;
每组输出占一行。
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;
}