Problem Descriptiongiven a sequence,...... N, your job is to calculate all the possible sub-sequences the sum of the sub-sequence is M.
Inputinput contains multiple test cases. Each case contains the integers n, m (1 <= N, M <= 1000000000). Input ends with N = m = 0.
Outputfor each test case, print all the possible sub-sequence, it sum is m.the format was show in the sample Below.pri NT a blank line after each test case.
Ideas:
If the answer is [i,j], then there is: j2+j-i2-i=2m (j+i+1) (j-i) =2m
The 2M is decomposed, and then judged, and, to make a mess,
Code:
intn,m;intMain () { while(cin>>n>>m,n| |m) {m*=2; intT= (int) sqrt (m+0.5); REP2 (I,t,1){ if(m%i==0){ intb; A=m/i, b=i; intx, y; X= (a-b-1)/2; Y= (a+b-1)/2; if(x<0|| Y>n | | (2*x+1)! = (a) | | (2*y+1)! = (a+b))Continue; printf ("[%d,%d]\n", x+1, y); }} cout<<Endl; }}
HDU 2058 The sum problem (simple factoring,,)