Time Limit: 1s Memory Limit: 32MB
问题描述
Given a sequence 1,2,3,…,N, your job is to calculate the number of sub-sequences that the sum of the sub-sequence is M.
输入描述
The first line contains a single integer T(1≤T≤10), indicating the number of test cases. Each case contains two integers N,M(1≤N,M≤1000).
输出描述
For each case, print a number in a line.
输入样例
2
20 10
50 30
输出样例
2
4
样例解释
For the first case: the sum of sub-sequence [1, 4] and [10, 10] is 10.
【题目链接】:
【题解】
傻逼题
【完整代码】
#include <bits/stdc++.h>
using namespace std;
int main()
{
freopen("H.in","r",stdin);
freopen("H.out","w",stdout);
int t;cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
int ans=0;
for(int i=1;i<=n;++i)
{
int sum=0;
for(int j=i;j<=n;++j)
{
sum+=j;
if(sum==m)
ans++;
else if(sum>m)
break;
}
}
cout<<ans<<endl;
}
return 0;
}