HDU 2058 The sum problem (simple factoring,,)

Source: Internet
Author: User

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,,)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.