Given a sequence 1,2,3,......N, your job is to calculate all the possible sub-sequences that the sum of the sub-sequence is M.
20 10 50 30 0 0
[1,4] [10,10] [4,8] [6,9] [9,11] [30,30]
#include<stdio.h>
#include<math.h>
int main()
{
long long a, m, n, k, x;
while(scanf("%lld%lld", &n, &m)!=EOF, m&&n)
{
x=(int)sqrt(2*m);
for(k=x;k>0;k--)
{
a=m/k-(k-1)/2;
if((2*a-1+k)*k==2*m)
printf("[%lld,%lld]\n", a, a+k-1);
}
printf("\n");
}
return 0;
}