The sum problem

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.

InputInput contains multiple test cases. each case contains two integers N, M( 1 <= N, M <= 1000000000).input ends with N = M = 0.
OutputFor each test case, print all the possible sub-sequence that its sum is M.The format is show in the sample below.print a blank line after each test case.
Sample Input20 10 50 30 0 0Sample Output```
[1,4]
[10,10]
[4,8]
[6,9]
[9,11]
[30,30]

#include

#include

using  namespace  std;

int main(){

    ios::sync_with_stdio(0);

    int n,m;

    while(cin >> n >> m){

        if(n == 0 && m == 0) break;

    for(int i = sqrt(2*m); i >= 1; i--){

        int g = m - i*(i+1)/2;

        if(g % i == 0){

            printf("[%d,%d]\n",1+g/i,i+g/i);

        }

    }    

    puts("");

}

    return  0;

}



Magical Bamboos

In a magical forest, there exists N bamboos that don't quite get cut down the way you would expect.

Originally, the height of the ith bamboo is equal to hi. In one move, you can push down a bamboo and decrease its height by one, but this move magically causes all the other bamboos to increase in height by one.

If you can do as many moves as you like, is it possible to make all the bamboos have the same height?

Input

The first line of input is T – the number of test cases.

The first line of each test case contains an integer N (1 ≤ N ≤ 105) - the number of bamboos.

The second line contains N space-separated integers hi (1 ≤ hi ≤ 105) - the original heights of the bamboos.

Output

For each test case, output on a single line "yes” (without quotes), if you can make all the bamboos have the same height, and "no" otherwise.

Example
Input
2
3
2 4 2
2
1 2
Output
yes
no

这一题 只要同组数据奇偶性相同就可以。
#include<iostream>
#include<cmath>
using namespace std;
int main(){     ios::sync_with_stdio(0);     int n,m;
        cin >> m;     int a,b;     cin >> a;     m--;     int g = a & 1;
        int f = 1;
        while(m--){     cin >> a;     if((a & 1) != g){         f = 0;     }
                }  if(f) cout << "yes\n";
        else cout << "no\n";
    }
return 0;
}